事件网格订阅架构Event Grid subscription schema

若要创建一个事件网格订阅,将请求发送到创建事件订阅操作。To create an Event Grid subscription, you send a request to the Create Event subscription operation. 使用以下格式:Use the following format:

PUT /subscriptions/{subscription-id}/resourceGroups/{group-name}/providers/{resource-provider}/{resource-type}/{resource-name}/Microsoft.EventGrid/eventSubscriptions/{event-type-definitions}?api-version=2018-01-01

例如,若要在名为 examplegroup 的资源组中创建名为 examplestorage 的存储帐户的事件订阅,请使用以下格式:For example, to create an event subscription for a storage account named examplestorage in a resource group named examplegroup, use the following format:

PUT /subscriptions/{subscription-id}/resourceGroups/examplegroup/providers/Microsoft.Storage/storageaccounts/examplestorage/Microsoft.EventGrid/eventSubscriptions/{event-type-definitions}?api-version=2018-01-01

事件订阅名称的长度必须为 3-64 个字符,并且只能包含 a-z、A-Z、0-9 和“-”。The Event Subscription name must be 3-64 characters in length and can only contain a-z, A-Z, 0-9, and "-". 本文介绍请求正文的属性和架构。The article describes the properties and schema for the body of the request.

事件订阅属性Event subscription properties

属性Property 类型Type 描述Description
destinationdestination objectobject 定义终结点的对象。The object that defines the endpoint.
filterfilter objectobject 用于筛选事件类型的可选字段。An optional field for filtering the types of events.

目标对象destination object

属性Property 类型Type 说明Description
endpointTypeendpointType 字符串string 订阅(webhook/HTTP、事件中心或队列)的终结点类型。The type of endpoint for the subscription (webhook/HTTP, Event Hub, or queue).
endpointUrlendpointUrl 字符串string 此事件订阅中的事件的目标 URL。The destination URL for events in this event subscription.

筛选器对象filter object

属性Property 类型Type 说明Description
includedEventTypesincludedEventTypes arrayarray 当事件消息中的事件类型与这些事件类型名称之一完全匹配时匹配。Match when the event type in the event message is an exact match to one of these event type names. 当事件名称与事件源的已注册事件类型名称不匹配时,将引发错误。Raises an error when event name does not match the registered event type names for the event source. 默认匹配所有事件类型。Default matches all event types.
subjectBeginsWithsubjectBeginsWith 字符串string 事件消息中使用者字段的前缀匹配筛选器。A prefix-match filter to the subject field in the event message. 默认或空字符串匹配所有类型。The default or empty string matches all.
subjectEndsWithsubjectEndsWith 字符串string 事件消息中使用者字段的后缀匹配筛选器。A suffix-match filter to the subject field in the event message. 默认或空字符串匹配所有类型。The default or empty string matches all.
isSubjectCaseSensitiveisSubjectCaseSensitive 字符串string 用于筛选器的区分大小写匹配的控件。Controls case-sensitive matching for filters.
enableAdvancedFilteringOnArraysenableAdvancedFilteringOnArrays booleanboolean 启用在高级筛选中对键使用数组。Enables using arrays for keys in advanced filtering. 有关详细信息,请参阅高级筛选For more information, see Advanced filtering.

订阅架构示例Example subscription schema

{
  "properties": {
    "destination": {
      "endpointType": "webhook",
      "properties": {
          "endpointUrl": "https://example.chinacloudsites.cn/api/HttpTriggerCSharp1?code=VXbGWce53l48Mt8wuotr0GPmyJ/nDT4hgdFj9DpBiRt38qqnnm5OFg=="
      }
    },
    "filter": {
      "includedEventTypes": [ "Microsoft.Storage.BlobCreated", "Microsoft.Storage.BlobDeleted" ],
      "subjectBeginsWith": "/blobServices/default/containers/mycontainer/log",
      "subjectEndsWith": ".jpg",
      "isSubjectCaseSensitive ": "true"
    }
  }
}

后续步骤Next steps