Implementing cross-region event delivery with Event Grid Domain.
TypeScriptTo set up cross-region event delivery using Azure Event Grid Domain, we need to consider the following:
-
Event Grid Domain: An event grid domain provides you with a single endpoint to manage and route your events. Your application components can publish events to this domain, and it will handle routing these events to different domain topics that you've set up based on the event routes you configure.
-
Domain Topics: Topics within an Event Grid domain. Publish events to a domain topic, and Event Grid handles routing them to the appropriate event subscription.
-
Event Subscriptions: Subscriptions to a topic or domain. When an event is published to a topic that matches the subscription's filter criteria, Event Grid sends the event to the webhook URL or other event handler specified in the subscription.
-
Filters: Defined within the event subscriptions, they allow you to specify which events you are interested in. An event subscription without a filter will receive all events for the associated topic.
Below is an example in TypeScript using Pulumi for provisioning an Azure Event Grid Domain, creating a Domain Topic within it, and setting up an Event Subscription to listen to events. Detailed comments and explanations are provided within the code on what each part does:
import * as pulumi from "@pulumi/pulumi"; import * as azure from "@pulumi/azure-native"; // Set up an Azure Resource Group const resourceGroup = new azure.resources.ResourceGroup("rg"); // Create the Event Grid Domain const domain = new azure.eventgrid.Domain("domain", { resourceGroupName: resourceGroup.name, location: resourceGroup.location, }); // Create a Domain Topic within the Event Grid Domain const domainTopic = new azure.eventgrid.DomainTopic("domainTopic", { resourceGroupName: resourceGroup.name, domainName: domain.name, domainTopicName: "sampleDomainTopic", }); // Create an Event Subscription to the Domain Topic. // Here, you would replace the `endpoint.url` with the endpoint to which the events should be delivered. // The 'filter' section is optional and is used to define which events you want to subscribe to. const eventSubscription = new azure.eventgrid.DomainTopicEventSubscription("eventSubscription", { domainName: domain.name, topicName: domainTopic.name, resourceGroupName: resourceGroup.name, // Define the event handler (endpoint) that will process the events destination: { endpointType: "WebHook", properties: { // Use your endpoint's URL that is supposed to handle the incoming events. endpointUrl: "<YOUR_WEBHOOK_ENDPOINT_URL>", }, }, // Specify filtering rules if required (optional) filter: { includedEventTypes: ["Microsoft.Storage.BlobCreated", "Microsoft.Resources.ResourceWriteSuccess"], subjectEndsWith: ".jpg", subjectBeginsWith: "sample/", isSubjectCaseSensitive: false, }, }); // Export the primary domain endpoint for the Event Grid Domain export const primaryEndpoint = domain.endpoint;
This code defines a stack that sets up an Azure Event Grid Domain with one topic and a subscription where:
- A new resource group
resourceGroup
is created. - An event grid domain
domain
is provisioned within the resource group which acts as a central point to publish and manage events. - A domain topic
domainTopic
is created inside the Event Grid domain. This represents a specific channel within the domain that events can be published to. - An event subscription
eventSubscription
is created against the domain topic. This subscription is configured to trigger a webhook endpoint - which you need to specify - whenever an event matching the filter criteria is published to the topic.
Make sure to replace
<YOUR_WEBHOOK_ENDPOINT_URL>
with the actual URL where your application or service is listening for events.To run this Pulumi program, you'll need to have the Pulumi CLI installed and configured for Azure. Save the above code to a
index.ts
file in a directory and runpulumi up
to preview and apply the changes. It will provision the resources as per the above configuration.-