title | description | ms.topic | ms.date |
---|---|---|---|
Service Bus queues and topics as event handlers for Azure Event Grid events |
Describes how you can use Service Bus queues and topics as event handlers for Azure Event Grid events. |
conceptual |
09/30/2021 |
An event handler is the place where the event is sent. The handler takes some further action to process the event. Several Azure services are automatically configured to handle events and Azure Service Bus is one of them.
You can use a Service queue or topic as a handler for events from Event Grid.
Note
Session enabled queues are not supported as event handlers for Azure Event Grid events
You can route events in Event Grid directly to Service Bus queues for use in buffering or command & control scenarios in enterprise applications.
In the Azure portal, while creating an event subscription, select Service Bus Queue as endpoint type and then click select an endpoint to choose a Service Bus queue.
For Azure CLI, the following example subscribes and connects an event grid topic to a Service Bus queue:
az eventgrid event-subscription create \
--name <my-event-subscription> \
--source-resource-id /subscriptions/{SubID}/resourceGroups/{RG}/providers/Microsoft.EventGrid/topics/topic1 \
--endpoint-type servicebusqueue \
--endpoint /subscriptions/{SubID}/resourceGroups/TestRG/providers/Microsoft.ServiceBus/namespaces/ns1/queues/queue1
You can route events in Event Grid directly to Service Bus topics to handle Azure system events with Service Bus topics, or for command & control messaging scenarios.
In the Azure portal, while creating an event subscription, select Service Bus Topic as endpoint type and then click select and endpoint to choose a Service Bus topic.
For Azure CLI, the following example subscribes and connects an event grid topic to a Service Bus topic:
az eventgrid event-subscription create \
--name <my-event-subscription> \
--source-resource-id /subscriptions/{SubID}/resourceGroups/{RG}/providers/Microsoft.EventGrid/topics/topic1 \
--endpoint-type servicebustopic \
--endpoint /subscriptions/{SubID}/resourceGroups/TestRG/providers/Microsoft.ServiceBus/namespaces/ns1/topics/topic1
[!INCLUDE event-grid-message-headers]
When sending an event to a Service Bus queue or topic as a brokered message, the messageid
of the brokered message is an internal system ID.
The internal system ID for the message will be maintained across redelivery of the event so that you can avoid duplicate deliveries by turning on duplicate detection on the service bus entity. We recommend that you enable duration of the duplicate detection on the Service Bus entity to be either the time-to-live (TTL) of the event or max retry duration, whichever is longer.
{
"properties":
{
"destination":
{
"endpointType": "ServiceBusQueue",
"properties":
{
"resourceId": "/subscriptions/<AZURE SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.ServiceBus/namespaces/<SERVICE BUS NAMESPACE NAME>/queues/<SERVICE BUS QUEUE NAME>"
}
},
"eventDeliverySchema": "EventGridSchema"
}
}
{
"properties": {
"deliveryWithResourceIdentity":
{
"identity":
{
"type": "SystemAssigned"
},
"destination":
{
"endpointType": "ServiceBusQueue",
"properties":
{
"resourceId": "/subscriptions/<AZURE SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.ServiceBus/namespaces/<SERVICE BUS NAMESPACE NAME>/queues/<SERVICE BUS QUEUE NAME>"
}
}
},
"eventDeliverySchema": "EventGridSchema"
}
}
{
"properties":
{
"destination":
{
"endpointType": "ServiceBusTopic",
"properties":
{
"resourceId": "/subscriptions/<AZURE SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.ServiceBus/namespaces/<SERVICE BUS NAMESPACE NAME>/topics/<SERVICE BUS TOPIC NAME>"
}
},
"eventDeliverySchema": "EventGridSchema"
}
}
{
"properties":
{
"deliveryWithResourceIdentity":
{
"identity":
{
"type": "SystemAssigned"
},
"destination":
{
"endpointType": "ServiceBusTopic",
"properties":
{
"resourceId": "/subscriptions/<AZURE SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.ServiceBus/namespaces/<SERVICE BUS NAMESPACE NAME>/topics/<SERVICE BUS TOPIC NAME>"
}
}
},
"eventDeliverySchema": "EventGridSchema"
}
}
Event subscriptions allow you to set up HTTP headers that are included in delivered events. This capability allows you to set custom headers that are required by a destination. You can set custom headers on the events that are delivered to Azure Service Bus queues and topics.
Azure Service Bus supports the use of following message properties when sending single messages.
Header name | Header type |
---|---|
MessageId |
Dynamic |
PartitionKey |
Static or dynamic |
SessionId |
Static or dynamic |
CorrelationId |
Static or dynamic |
Label |
Static or dynamic |
ReplyTo |
Static or dynamic |
ReplyToSessionId |
Static or dynamic |
To |
Static or dynamic |
ViaPartitionKey |
Static or dynamic |
Note
- The default value of
MessageId
is the internal ID of the Event Grid event. You can override it. For example,data.field
. - You can only set either
SessionId
orMessageId
.
For more information, see Custom delivery properties.
See the Event handlers article for a list of supported event handlers.