事件处理程序是公开终结点的任何系统,也是事件网格发送的事件的目标。 事件处理程序接收到事件后,会对其进行处理,并使用事件负载来执行某些逻辑,这可能会导致新事件的发生。
配置事件网格以将事件发送到目标的方式是通过创建事件订阅。 可以通过 Azure CLI、management SDK 或使用 2020-10-15-preview API 版本的直接 HTTPS 调用来完成。
通常,Kubernetes 上的事件网格可以通过 Webhook 将事件发送到任何目标。 Webhook 是事件网格有权访问的服务或工作负荷公开的 HTTP(s) 终结点。 Webhook 可以是托管在同一群集、同一网络空间、云、本地或事件网格可访问的任何位置的工作负荷。
重要
Azure Arc 支持的 Kubernetes 上的事件网格目前处于公开预览阶段。 此预览版在提供时没有附带服务级别协议,不建议将其用于生产工作负荷。 某些功能可能不受支持或者受限。 有关详细信息,请参阅 Microsoft Azure 预览版的使用条款。
通过 Webhooks,事件网格支持在 Kubernetes 群集上托管以下目标:
- 在 Kubernetes 上通过 Azure Arc 使用 Azure 应用服务。
- 通过 Azure Arc 在 Kubernetes 上实现 Azure Functions。
- 在 Kubernetes 上使用 Azure Arc 的 Azure 逻辑应用。
除了 Webhooks,Kubernetes 上的事件网格还可以将事件发送到托管在 Azure 上的以下目标:
- Azure 事件网格 使用 Webhooks
- 仅Azure Functions 只使用 Webhook
- 使用Azure 事件中心 的 Azure 资源管理器 资源 ID
- 使用 Azure 资源管理器 资源 ID 的 Azure 服务总线 主题或队列
- 使用其 Azure 资源管理器 资源 ID 的 Azure 存储 队列
功能对等
Kubernetes 上的事件网格在功能方面与 Azure 事件网格对事件订阅的支持具有良好的相似性。 以下列表枚举事件订阅功能的主要差异。 除了这些差异之外,还可以使用 Azure 事件网格 的 REST api 版本 2020-10-15-preview作为在 Kubernetes 上的事件网格上管理事件订阅时的参考。
- 使用 REST API 版本 2020-10-15-preview。
- 不支持Azure Functions 的 Azure 事件网格触发器。 可以使用 WebHook 目标类型将事件传送到Azure Functions。
- 没有 死信位置 支持。 这意味着你不能在事件订阅有效负载中使用
properties.deadLetterDestination。 - 尚不支持Azure 中继作为目标的混合连接。
- 仅支持 CloudEvents 架构。 支持的架构值为“CloudEventSchemaV1_0”。 云事件架构可扩展且基于开放标准。
- 标签(properties.labels)不适用于 Kubernetes 上的事件网格。 因此,它们不可用。
- 不支持具有资源标识的交付。 因此,不支持任何 事件订阅标识 的属性。
- 尚不支持目标终结点验证 。
事件订阅中的事件筛选
配置事件订阅的另一个重要方面是选择要传递到目标的事件。 有关详细信息,请参阅 事件筛选。
示例目标配置
下面是一些基本示例配置,具体取决于预期目标。
网络钩子
若要发布到 WebHook 终结点,请将 endpointType 设置为 WebHook 并提供以下内容:
endpointUrl:WebHook 接入点 URL
{ "properties": { "destination": { "endpointType": "WebHook", "properties": { "endpointUrl": "<your-webhook-endpoint>" } } } }
Azure 事件网格
若要发布到Azure 事件网格云终结点,请将 endpointType 设置为 WebHook并提供:
endpointUrl:云中Azure 事件网格主题 URL,API 版本参数设置为 2018-01-01,
aeg-sas-key设置为 URL 编码的 SAS 密钥。{ "properties": { "destination": { "endpointType": "WebHook", "properties": { "endpointUrl": "<your-event-grid-cloud-topic-endpoint-url>?api-version=2018-01-01&aeg-sas-key=urlencoded(sas-key-value)" } } } }
事件中心
若要发布到事件中心,请将 endpointType 设置为 eventHub,并配置以下参数:
resourceId:特定事件中心的资源 ID。
{ "properties": { "destination": { "endpointType": "eventHub", "properties": { "resourceId": "<Azure Resource ID of your event hub>" } } } }
服务总线队列
若要发布到服务总线队列,请将 endpointType 设置为 serviceBusQueue并提供:
resourceId:特定服务总线队列的资源 ID。
{ "properties": { "destination": { "endpointType": "serviceBusQueue", "properties": { "resourceId": "<Azure Resource ID of your Service Bus queue>" } } } }
服务总线主题
若要发布到服务总线主题,请将 endpointType 设置为 serviceBusTopic并提供:
resourceId:特定服务总线主题的资源 ID。
{ "properties": { "destination": { "endpointType": "serviceBusTopic", "properties": { "resourceId": "<Azure Resource ID of your Service Bus topic>" } } } }
存储队列
若要发布到存储队列,请将 endpointType 设置为 storageQueue 并提供:
queueName:要发布到的Azure 存储队列的名称。
resourceID:包含队列的存储帐户Azure资源 ID。
{ "properties": { "destination": { "endpointType": "storageQueue", "properties": { "queueName": "<your-storage-queue-name>", "resourceId": "<Azure Resource ID of your Storage account>" } } } }
后续步骤
- 将 筛选器配置 添加到事件订阅,以选择要传递的事件。
- 若要了解 Kubernetes Azure Arc 上的事件网格支持的架构,请参阅 Kubernetes 上的 Event 网格 - 事件架构。