Kubernetes 上的事件网格中的事件处理程序目标

事件处理程序是公开终结点的任何系统,也是事件网格发送的事件的目标。 事件处理程序接收到事件后,会对其进行处理,并使用事件负载来执行某些逻辑,这可能会导致新事件的发生。

配置事件网格以将事件发送到目标的方式是通过创建事件订阅。 可以通过 Azure CLI管理 SDK 或使用 2020-10-15 预览版 API 版本的直接 HTTPS 调用来完成。

通常,Kubernetes 上的事件网格可以通过 Webhook 将事件发送到任何目标。 Webhook 是事件网格有权访问的服务或工作负荷公开的 HTTP(s) 终结点。 Webhook 可以是托管在同一群集、同一网络空间、云、本地或事件网格可访问的任何位置的工作负荷。

重要

Azure Arc 上的 Kubernetes 事件网格目前正处于公共预览阶段。 此预览版在提供时没有附带服务级别协议,不建议将其用于生产工作负荷。 某些功能可能不受支持或者受限。 有关详细信息,请参阅 Microsoft Azure 预览版补充使用条款

通过 Webhooks,事件网格支持在 Kubernetes 群集上托管以下目标:

  • 将 Kubernetes 上的 Azure 应用服务与 Azure Arc 配合使用。
  • 通过 Azure Arc 在 Kubernetes 上运行 Azure Functions。
  • 将 Kubernetes 上的 Azure 逻辑应用与 Azure Arc 配合使用。

除了 Webhook,Kubernetes 上的事件网格还可以将事件发送到 Azure 上托管的以下目标:

  • 使用 Webhook 的 Azure 事件网格
  • Azure Functions 仅使用 Webhooks
  • 使用 Azure 资源管理器资源 ID 的 Azure 事件中心
  • 使用 Azure 资源管理器资源 ID 的 Azure 服务总线主题或队列
  • 使用 Azure 资源管理器资源 ID 的 Azure 存储队列

功能对等

Kubernetes 上的事件网格在功能上与 Azure 事件网格对事件订阅的支持具有良好的相似性。 以下列表枚举事件订阅功能的主要差异。 除了这些差异之外,还可以在 Kubernetes 上的事件网格上管理事件订阅时,使用 Azure 事件网格的 REST API 版本 2020-10-15-preview 作为参考。

  1. 使用 REST API 版本 2020-10-15-preview
  2. Azure Functions 的 Azure 事件网格触发器不受支持。 可以使用 WebHook 目标类型将事件传送到 Azure Functions。
  3. 没有 死信位置 支持。 这意味着你不能在事件订阅有效负载中使用 properties.deadLetterDestination
  4. 尚不支持使用 Azure 中继的混合连接作为目标。
  5. 仅支持 CloudEvents 架构。 支持的架构值为“CloudEventSchemaV1_0”。 云事件架构可扩展且基于开放标准。
  6. 标签(properties.labels)不适用于 Kubernetes 上的事件网格。 因此,它们不可用。
  7. 不支持具有资源标识的交付。 因此,不支持任何 事件订阅标识 的属性。
  8. 尚不支持目标终结点验证

事件订阅中的事件筛选

配置事件订阅的另一个重要方面是选择要传递到目标的事件。 有关详细信息,请参阅 事件筛选

示例目标配置

下面是一些基本示例配置,具体取决于预期目标。

网络钩子

若要发布到 WebHook 终结点,请将 endpointType 设置为 WebHook 并提供以下内容:

  • endpointUrl:WebHook 接入点 URL

        {
          "properties": {
            "destination": {
              "endpointType": "WebHook",
              "properties": {
                "endpointUrl": "<your-webhook-endpoint>"
              }
            }
          }
        }
    

Azure 事件网格

若要发布到 Azure Event Grid 云终结点,请将 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>"
          }
        }
      }
    }
    

后续步骤