您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

Azure 事件网格事件架构Azure Event Grid event schema

本文介绍为所有事件提供的属性和架构。This article describes the properties and schema that are present for all events. 事件由 5 个所需的字符串属性和 1 个 所需的数据对象构成。 Events consist of a set of five required string properties and a required data object. 这些属性在任何发布服务器的所有事件中通用。The properties are common to all events from any publisher. 数据对象具有特定于每个发布者的属性。The data object has properties that are specific to each publisher. 对于系统主题,这些属性特定于资源提供程序,例如 Azure 存储或 Azure 事件中心。For system topics, these properties are specific to the resource provider, such as Azure Storage or Azure Event Hubs.

事件源会将事件发送到数组中的 Azure 事件网格(其中可包含多个事件对象)。Event sources send events to Azure Event Grid in an array, which can have several event objects. 将事件发布到事件网格主题时,数组的总大小最大可为 1 MB。When posting events to an event grid topic, the array can have a total size of up to 1 MB. 数组中的每个事件被限制为 64 KB (正式版) 或 1 MB (预览版)。Each event in the array is limited to 64 KB (General Availability) or 1 MB (preview). 事件或数组超出大小限制时会收到响应“413 有效负载太大” 。If an event or the array is greater than the size limits, you receive the response 413 Payload Too Large.


事件的大小高达 64 KB 介绍了通过正式版 (GA) 服务级别协议 (SLA)。An event of size up to 64 KB is covered by General Availability (GA) Service Level Agreement (SLA). 大小最多的事件的支持 1 MB 目前处于预览状态。The support for an event of size up to 1 MB is currently in preview. 超过 64 KB 的事件是按 64 KB 的增量计费。Events over 64 KB are charged in 64-KB increments.

事件网格会将事件发送给具有单个事件的数组中的订阅者。Event Grid sends the events to subscribers in an array that has a single event. 此行为在将来可能会更改。This behavior may change in the future.

可以在事件架构存储中找到事件网格事件的 JSON 架构和每个 Azure 发布服务器的数据负载。You can find the JSON schema for the Event Grid event and each Azure publisher's data payload in the Event Schema store.

事件架构Event schema

以下示例显示所有事件发布者使用的属性:The following example shows the properties that are used by all event publishers:

    "topic": string,
    "subject": string,
    "id": string,
    "eventType": string,
    "eventTime": string,
    "dataVersion": string,
    "metadataVersion": string

例如,为 Azure Blob 存储事件发布的架构是:For example, the schema published for an Azure Blob storage event is:

    "topic": "/subscriptions/{subscription-id}/resourceGroups/Storage/providers/Microsoft.Storage/storageAccounts/xstoretestaccount",
    "subject": "/blobServices/default/containers/oc2d2817345i200097container/blobs/oc2d2817345i20002296blob",
    "eventType": "Microsoft.Storage.BlobCreated",
    "eventTime": "2017-06-26T18:41:00.9584103Z",
    "id": "831e1650-001e-001b-66ab-eeb76e069631",
    "data": {
      "api": "PutBlockList",
      "clientRequestId": "6d79dbfb-0e37-4fc4-981f-442c9ca65760",
      "requestId": "831e1650-001e-001b-66ab-eeb76e000000",
      "eTag": "0x8D4BCC2E4835CD0",
      "contentType": "application/octet-stream",
      "contentLength": 524288,
      "blobType": "BlockBlob",
      "url": "https://oc2d2817345i60006.blob.core.windows.net/oc2d2817345i200097container/oc2d2817345i20002296blob",
      "sequencer": "00000000000004420000000000028963",
      "storageDiagnostics": {
        "batchId": "b68529f3-68cd-4744-baa4-3c0498ec19f0"
    "dataVersion": "",
    "metadataVersion": "1"

事件属性Event properties

所有事件均具有以下相同的顶级数据:All events have the same following top-level data:

属性Property 类型Type 描述Description
topictopic stringstring 事件源的完整资源路径。Full resource path to the event source. 此字段不可写入。This field isn't writeable. 事件网格提供此值。Event Grid provides this value.
subjectsubject stringstring 事件主题的发布者定义路径。Publisher-defined path to the event subject.
eventTypeeventType stringstring 此事件源的一个注册事件类型。One of the registered event types for this event source.
eventTimeeventTime stringstring 基于提供程序 UTC 时间的事件生成时间。The time the event is generated based on the provider's UTC time.
idid stringstring 事件的唯一标识符。Unique identifier for the event.
datadata objectobject 特定于资源提供程序的事件数据。Event data specific to the resource provider.
dataVersiondataVersion stringstring 数据对象的架构版本。The schema version of the data object. 发布者定义架构版本。The publisher defines the schema version.
metadataVersionmetadataVersion stringstring 事件元数据的架构版本。The schema version of the event metadata. 事件网格定义顶级属性的架构。Event Grid defines the schema of the top-level properties. 事件网格提供此值。Event Grid provides this value.

若要了解数据对象中的属性,请参阅事件源:To learn about the properties in the data object, see the event source:

对于自定义主题,事件发布者确定数据对象。For custom topics, the event publisher determines the data object. 顶级数据应具有与标准资源所定义事件相同的字段。The top-level data should have the same fields as standard resource-defined events.

将事件发布到自定义主题时,可为事件创建主题,便于订阅者们了解他们是否对该事件感兴趣。When publishing events to custom topics, create subjects for your events that make it easy for subscribers to know whether they're interested in the event. 订阅者使用主题来筛选和路由事件。Subscribers use the subject to filter and route events. 请考虑为事件发生的位置提供路径,以便订阅者可根据该路径的片段进行筛选。Consider providing the path for where the event happened, so subscribers can filter by segments of that path. 通过路径,订阅者可精确或宽泛地筛选事件。The path enables subscribers to narrowly or broadly filter events. 例如,如果在主题中提供一个由三个片段构成的路径(如 /A/B/C),订阅者可根据第一个片段 /A 进行筛选,获取范围较宽泛的一组事件。For example, if you provide a three segment path like /A/B/C in the subject, subscribers can filter by the first segment /A to get a broad set of events. 这些订阅者会获取主题为 /A/B/C/A/D/E 这样的事件。Those subscribers get events with subjects like /A/B/C or /A/D/E. 其他订阅者可通过 /A/B 进行筛选,这样可以获取范围更精确的一组事件。Other subscribers can filter by /A/B to get a narrower set of events.

有时,需要提供有关发生事件更详细的信息才能查找到所需主题。Sometimes your subject needs more detail about what happened. 例如,将文件添加到容器时,“存储帐户”发布服务器提供主题 /blobServices/default/containers/<container-name>/blobs/<file>For example, the Storage Accounts publisher provides the subject /blobServices/default/containers/<container-name>/blobs/<file> when a file is added to a container. 订阅者可以按路径 /blobServices/default/containers/testcontainer 进行筛选,获取有关该容器而非存储帐户中其他容器的所有事件。A subscriber could filter by the path /blobServices/default/containers/testcontainer to get all events for that container but not other containers in the storage account. 订阅者还可通过使用后缀 .txt 进行筛选或路由,来达到仅处理文本文件的目的。A subscriber could also filter or route by the suffix .txt to only work with text files.

后续步骤Next steps