Azure 事件网格中的自定义主题Custom topics in Azure Event Grid

事件网格主题提供一个可供源在其中发送事件的终结点。An 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.

自定义主题是应用程序和第三方的主题。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.

设计应用程序时,可以灵活地决定要创建多少个主题。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 schema

有关事件架构的详细概述,请参阅 Azure 事件网格事件架构For a detailed overview of event schema, see Azure Event Grid event schema. 对于自定义主题,事件发布者确定数据对象 。For custom topics, the event publisher determines the data object. 顶级数据应具有与标准资源所定义事件相同的字段。The top-level data should have the same fields as standard resource-defined events.

[
  {
    "topic": string,
    "subject": string,
    "id": string,
    "eventType": string,
    "eventTime": string,
    "data":{
      object-unique-to-each-publisher
    },
    "dataVersion": string,
    "metadataVersion": string
  }
]

以下部分提供了一些指向教程的链接,这些教程分别介绍如何使用 Azure 门户、CLI、PowerShell 和 Azure 资源管理器 (ARM) 模板来创建自定义主题。The following sections provide links to tutorials to create custom topics using Azure portal, CLI, PowerShell, and Azure Resource Manager (ARM) templates.

Azure 门户教程Azure portal tutorials

标题Title 说明Description
快速入门:使用 Azure 门户创建和路由自定义事件Quickstart: create and route custom events with the Azure portal 说明如何使用门户发送自定义事件。Shows how to use the portal to send custom events.
快速入门:将自定义事件路由到 Azure 队列存储Quickstart: route custom events to Azure Queue storage 说明如何将自定义事件发送到队列存储。Describes how to send custom events to a Queue storage.
如何:发布到自定义主题How to: post to custom topic 说明如何将事件发布到自定义主题。Shows how to post an event to a custom topic.

Azure CLI 教程Azure CLI tutorials

标题Title 说明Description
快速入门:使用 Azure CLI 创建和路由自定义事件Quickstart: create and route custom events with Azure CLI 说明如何使用 Azure CLI 发送自定义事件。Shows how to use Azure CLI to send custom events.
Azure CLI:创建事件网格自定义主题Azure CLI: create Event Grid custom topic 用于创建自定义主题的示例脚本。Sample script that creates a custom topic. 该脚本检索终结点和密钥。The script retrieves the endpoint and a key.
Azure CLI:订阅自定义主题的事件Azure CLI: subscribe to events for a custom topic 用于创建自定义主题的订阅的示例脚本。Sample script that creates a subscription for a custom topic. 它将事件发送到 WebHook。It sends events to a WebHook.

Azure PowerShell 教程Azure PowerShell tutorials

标题Title 说明Description
快速入门:使用 Azure PowerShell 创建和路由自定义事件Quickstart: create and route custom events with Azure PowerShell 说明如何使用 Azure PowerShell 发送自定义事件。Shows how to use Azure PowerShell to send custom events.
PowerShell:创建事件网格自定义主题PowerShell: create Event Grid custom topic 用于创建自定义主题的示例脚本。Sample script that creates a custom topic. 该脚本检索终结点和密钥。The script retrieves the endpoint and a key.
PowerShell:订阅自定义主题的事件PowerShell: subscribe to events for a custom topic 用于创建自定义主题的订阅的示例脚本。Sample script that creates a subscription for a custom topic. 它将事件发送到 WebHook。It sends events to a WebHook.

ARM 模板教程ARM template tutorials

标题Title 说明Description
资源管理器模板:自定义主题和 WebHook 终结点Resource Manager template: custom topic and WebHook endpoint 用于创建自定义主题及其订阅的资源管理器模板。A Resource Manager template that creates a custom topic and subscription for that custom topic. 它将事件发送到 WebHook。It sends events to a WebHook.
资源管理器模板:自定义主题和事件中心终结点Resource Manager template: custom topic and Event Hubs endpoint 用于创建自定义主题的订阅的资源管理器模板。A Resource Manager template that creates a subscription for a custom topic. 它将事件发送到 Azure 事件中心。It sends events to an Azure Event Hubs.

后续步骤Next steps

请参阅以下文章:See the following articles: