Azure 事件网格中的概念Concepts in Azure Event Grid

本文介绍了 Azure 事件网格中的主要概念。This article describes the main concepts in Azure Event Grid.


事件是完全描述系统中所发生情况的最小信息量。An event is the smallest amount of information that fully describes something that happened in the system. 每个事件都具有通用信息,如事件源、事件发生的时间和唯一标识符。Every event has common information like: source of the event, time the event took place, and unique identifier. 此外,每个事件还具有仅与特定事件类型相关的特定信息。Every event also has specific information that is only relevant to the specific type of event. 例如,与在 Azure 存储中创建的有关新文件的事件将包含有关该文件的详细信息,如 lastTimeModified 值。For example, an event about a new file being created in Azure Storage has details about the file, such as the lastTimeModified value. 再如,事件中心事件具有 Capture 文件的 URL。Or, an Event Hubs event has the URL of the Capture file.

一个事件允许的最大大小为 1 MB。The maximum allowed size for an event is 1 MB. 超过 64 KB 的事件以 64 KB 为增量计费。Events over 64 KB are charged in 64-KB increments. 至于在事件中发送的属性,请参阅 Azure 事件网格事件架构For the properties that are sent in an event, see Azure Event Grid event schema.


发布服务器是决定将事件发送到事件网格的用户或组织。A publisher is the user or organization that decides to send events to Event Grid. Microsoft 发布了几个 Azure 服务的事件。Microsoft publishes events for several Azure services. 可以从自己的应用程序发布事件。You can publish events from your own application. 在 Azure 外部托管服务的组织可以通过事件网格发布事件。Organizations that host services outside of Azure can publish events through Event Grid.

事件源Event sources

事件源即事件发生的位置。An event source is where the event happens. 每个事件源都与一个或多个事件类型相关。Each event source is related to one or more event types. 例如,Azure 存储是 blob 创建事件的事件源。For example, Azure Storage is the event source for blob created events. IoT 中心是设备创建的事件的事件源。IoT Hub is the event source for device created events. 你的应用程序是你定义的自定义事件的事件源。Your application is the event source for custom events that you define. 事件源负责将事件发送到事件网格。Event sources are responsible for sending events to Event Grid.

有关实现任何受支持的事件网格源的信息,请参阅 Azure 事件网格中的事件源For information about implementing any of the supported Event Grid sources, see Event sources in Azure Event Grid.


事件网格主题提供源在其中发送事件的终结点。The event grid topic provides an endpoint where the source sends events. 发布服务器创建事件网格主题,并决定事件源需要一个主题还是多个主题。The publisher creates the event grid topic, and decides whether an event source needs one topic or more than one topic. 主题用于收集相关事件。A topic is used for a collection of related events. 为了对某些类型的事件作出响应,订阅服务器将决定要订阅的主题。To respond to certain types of events, subscribers decide which topics to subscribe to.

系统主题是 Azure 服务(如 Azure 存储、Azure 事件中心和 Azure 服务总线)提供的内置主题。System topics are built-in topics provided by Azure services such as Azure Storage, Azure Event Hubs, and Azure Service Bus. 可以在 Azure 订阅中创建系统主题并订阅这些主题。You can create system topics in your Azure subscription and subscribe to them. 有关详细信息,请参阅系统主题概述For more information, see Overview of system topics.

自定义主题是应用程序和第三方的主题。Custom topics are application and third-party topics. 在创建或分配了对自定义主题的访问权限后,就会在订阅中看到该自定义主题。When you create or are assigned access to a custom topic, you see that custom topic in your subscription. 有关详细信息,请参阅自定义主题For more information, see Custom topics. 设计应用程序时,可以灵活地决定要创建多少个主题。When designing your application, you have flexibility when deciding how many topics to create. 对于大型解决方案,请为每个类别的相关事件创建自定义主题。For large solutions, create a custom topic for each category of related events. 例如,假设有一个应用程序发送与修改用户帐户和处理订单相关的事件。For example, consider an application that sends events related to modifying user accounts and processing orders. 任何事件处理程序都不太可能同时需要这两个类别的事件。It's unlikely any event handler wants both categories of events. 请创建两个自定义主题,让事件处理程序订阅其感兴趣的主题。Create two custom topics and let event handlers subscribe to the one that interests them. 对于小型解决方案,可能希望将所有事件发送到单个主题。For small solutions, you might prefer to send all events to a single topic. 事件订阅者可以筛选他们所需的事件类型。Event subscribers can filter for the event types they want.

事件订阅Event subscriptions

订阅告诉事件网格你有兴趣接收主题上的哪些事件。A subscription tells Event Grid which events on a topic you're interested in receiving. 在创建订阅时,你提供处理事件的终结点。When creating the subscription, you provide an endpoint for handling the event. 可以筛选发送到终结点的事件。You can filter the events that are sent to the endpoint. 可以按事件类型或使用者模式进行筛选。You can filter by event type, or subject pattern. 有关详细信息,请参阅事件网格订阅架构For more information, see Event Grid subscription schema.

有关创建订阅的示例,请参阅:For examples of creating subscriptions, see:

有关获取当前事件网格订阅的信息,请参阅查询事件网格订阅For information about getting your current event grid subscriptions, see Query Event Grid subscriptions.

事件订阅过期Event subscription expiration

事件订阅在该日期后自动过期。The event subscription is automatically expired after that date. 为仅在有限时间内需要的事件订阅设置一个过期日期,你不需要担心清理这些订阅。Set an expiration for event subscriptions that are only needed for a limited time and you don't want to worry about cleaning up those subscriptions. 例如,创建事件订阅来测试某个方案时,你可能想要设置过期日期。For example, when creating an event subscription to test a scenario, you might want to set an expiration.

有关设置过期日期的示例,请参阅使用高级筛选器进行订阅For an example of setting an expiration, see Subscribe with advanced filters.

事件处理程序Event handlers

从事件网格的角度看,事件处理程序是发送事件的位置。From an Event Grid perspective, an event handler is the place where the event is sent. 处理程序将执行一些进一步的操作来处理事件。The handler takes some further action to process the event. 事件网格支持多个处理程序类型。Event Grid supports several handler types. 可以使用受支持的 Azure 服务或你自己的 webhook 作为处理程序。You can use a supported Azure service or your own webhook as the handler. 根据处理程序的类型,事件网格遵循不同机制,以保证事件的传递。Depending on the type of handler, Event Grid follows different mechanisms to guarantee the delivery of the event. 对于 HTTP webhook 事件处理程序,在处理程序返回状态代码 200 - OK 之前,将重试事件。For HTTP webhook event handlers, the event is retried until the handler returns a status code of 200 - OK. 对于 Azure 存储队列,将重试事件,直到队列服务成功处理推送到队列的消息。For Azure Storage Queue, the events are retried until the Queue service successfully processes the message push into the queue.

有关实现任何受支持的事件网格处理程序的信息,请参阅 Azure 事件网格中的事件处理程序For information about implementing any of the supported Event Grid handlers, see Event handlers in Azure Event Grid.


事件网格可为订阅主题和发布主题提供安全性。Event Grid provides security for subscribing to topics, and publishing topics. 订阅时,必须对资源或事件网格主题具有足够的权限。When subscribing, you must have adequate permissions on the resource or event grid topic. 发布时,必须具有该主题的 SAS 令牌或密钥身份验证。When publishing, you must have a SAS token or key authentication for the topic. 有关详细信息,请参阅事件网格安全性和身份验证For more information, see Event Grid security and authentication.

事件传送Event delivery

如果事件网格无法确认订阅服务器的终结点已接收到事件,它将重新传递该事件。If Event Grid can't confirm that an event has been received by the subscriber's endpoint, it redelivers the event. 有关详细信息,请参阅事件网格消息传递和重试For more information, see Event Grid message delivery and retry.


使用自定义主题时,必须始终在数组中发布事件。When using a custom topic, events must always be published in an array. 对于低吞吐量方案,可采用单批;但对于大容量用例,建议在每次发布时对多个事件进行批处理,以实现更高的效率。This can be a batch of one for low-throughput scenarios, however, for high volume use cases, it's recommended that you batch several events together per publish to achieve higher efficiency. 批最大可以为 1 MB,事件的最大大小为 1 MB。Batches can be up to 1 MB and the maximum size of an event is 1 MB.

后续步骤Next steps