事件中心作为 Azure 事件网格事件的事件处理程序Event hub as an event handler for Azure Event Grid events

事件处理程序是发送事件的位置。An event handler is the place where the event is sent. 处理程序将执行操作来处理事件。The handler takes an action to process the event. 几个 Azure 服务已自动配置为处理事件,Azure 事件中心是其中之一。Several Azure services are automatically configured to handle events and Azure Event Hubs is one of them.

如果解决方案从事件网格获取事件的速度快于处理事件的速度,请使用事件中心。Use Event Hubs when your solution gets events from Event Grid faster than it can process the events. 事件位于事件中心后,应用程序可以按自己的计划处理事件中心的事件。Once the events are in an event hub, your application can process events from the event hub at its own schedule. 可以通过缩放事件处理来处理传入的事件。You can scale your event processing to handle the incoming events.

教程Tutorials

请看以下示例:See the following examples:

标题Title 说明Description
快速入门:使用 Azure CLI 将自定义事件路由到 Azure 事件中心Quickstart: Route custom events to Azure Event Hubs with Azure CLI 将自定义事件发送到事件中心以供应用程序处理。Sends a custom event to an event hub for processing by an application.
资源管理器模板:创建事件网格自定义主题,并将事件发送到事件中心Resource Manager template: Create an Event Grid custom topic and send events to an event hub 用于创建自定义主题的订阅的资源管理器模板。A Resource Manager template that creates a subscription for a custom topic. 它将事件发送到 Azure 事件中心。It sends events to an Azure Event Hubs.

Message headers

These are the properties you receive in the message headers:

Property name Description
aeg-subscription-name Name of the event subscription.
aeg-delivery-count Number of attempts made for the event.
aeg-event-type

Type of the event.

It can be one of the following values:

  • SubscriptionValidation
  • Notification
  • SubscriptionDeletion
aeg-metadata-version

Metadata version of the event.

For Event Grid event schema, this property represents the metadata version and for cloud event schema, it represents the spec version.

aeg-data-version

Data version of the event.

For Event Grid event schema, this property represents the data version and for cloud event schema, it doesn't apply.

aeg-output-event-id ID of the Event Grid event.

REST 示例(适用于 PUT)REST examples (for PUT)

事件中心Event hub

{
    "properties": 
    {
        "destination": 
        {
            "endpointType": "EventHub",
            "properties": 
            {
                "resourceId": "/subscriptions/<AZURE SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.EventHub/namespaces/<EVENT HUBS NAMESPACE NAME>/eventhubs/<EVENT HUB NAME>"
            }
        },
        "eventDeliverySchema": "EventGridSchema"
    }
}

事件中心 - 使用托管标识传送Event hub - delivery with managed identity

{
    "properties": {
        "deliveryWithResourceIdentity": 
        {
            "identity": 
            {
                "type": "SystemAssigned"
            },
            "destination": 
            {
                "endpointType": "EventHub",
                "properties": 
                {
                    "resourceId": "/subscriptions/<AZURE SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.EventHub/namespaces/<EVENT HUBS NAMESPACE NAME>/eventhubs/<EVENT HUB NAME>"
                }
            }
        },
        "eventDeliverySchema": "EventGridSchema"
    }
}

后续步骤Next steps

如需支持的事件处理程序的列表,请参阅事件处理程序一文。See the Event handlers article for a list of supported event handlers.