The documentation you are viewing is for Dapr v1.3 which is an older version of Dapr. For up-to-date documentation, see the latest version.

Azure Event Hubs

关于 Azure Event Hubs pubsub 组件的详细文档

配置

要安装 Azure Event Hubs pubsub,请创建一个类型为 pubsub.azure.eventhubs 的组件。 请参阅本指南,了解如何创建和应用 pubsub 配置。

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: eventhubs-pubsub
  namespace: default
spec:
  type: pubsub.azure.eventhubs
  version: v1
  metadata:
  - name: connectionString
    value: "Endpoint=sb://{EventHubNamespace}.servicebus.windows.net/;SharedAccessKeyName={PolicyName};SharedAccessKey={Key};EntityPath={EventHub}"
  - name: storageAccountName
    value: "myeventhubstorage"
  - name: storageAccountKey
    value: "112233445566778899"
  - name: storageContainerName
    value: "myeventhubstoragecontainer"

元数据字段规范

字段 必填 详情 示例
connectionString Y Event Hubs的连接地址 "Endpoint=sb://{EventHubNamespace}.servicebus.windows.net/;SharedAccessKeyName={PolicyName};SharedAccessKey={Key};EntityPath={EventHub}"
storageAccountName Y 用于EventProcessorHost的存储账户名称 "myeventhubstorage"
storageAccountKey Y 用于EventProcessorHost的存储账户密钥。 可以用secretKeyRef来引用密钥。 "112233445566778899"
storageContainerName Y 存储账户名称的存储容器名称。 "myeventhubstoragecontainer"

创建Azure Event Hub

请按照此处的说明设置 Azure Event Hubs。 由于本实施例使用Event Processor Host,你还需要一个Azure Storage Account。 请遵循此处的说明来管理存储帐户访问密钥。

请参阅这里,了解如何获取 Event Hubs 连接地址。 注意这不是Event Hubs命名空间。

为每个订阅者创建消费组

对于每个要订阅事件的Dapr应用,创建一个名称为dapr id的Event Hubs消费组。 例如,在 Kubernetes 上运行的 Dapr 应用程序的 dapr.io/app-id: "myapp"将需要一个名为myapp的Event Hubs消费组。

注意:Dapr将消费组的名称传递给EventHub,因此没有在元数据中提供。

Subscribing to Azure IoT Hub Events

Azure IoT Hub provides an endpoint that is compatible with Event Hubs, so the Azure Event Hubs pubsub component can also be used to subscribe to Azure IoT Hub events.

The device-to-cloud events created by Azure IoT Hub devices will contain additional IoT Hub System Properties, and the Azure Event Hubs pubsub component for Dapr will return the following as part of the response metadata:

System Property Name 说明
iothub-connection-auth-generation-id 发送消息的设备的 connectionDeviceGenerationId See IoT Hub device identity properties.
iothub-connection-auth-method The authentication method used to authenticate the device that sent the message.
iothub-connection-device-id 发送消息的设备的 deviceId。 See IoT Hub device identity properties.
iothub-connection-module-id 发送消息的设备的 moduleId。 See IoT Hub device identity properties.
iothub-enqueuedtime The date and time in RFC3339 format that the device-to-cloud message was received by IoT Hub.

For example, the headers of a delivered HTTP subscription message would contain:

{
  'user-agent': 'fasthttp',
  'host': '127.0.0.1:3000',
  'content-type': 'application/json',
  'content-length': '120',
  'iothub-connection-device-id': 'my-test-device',
  'iothub-connection-auth-generation-id': '637618061680407492',
  'iothub-connection-auth-method': '{"scope":"module","type":"sas","issuer":"iothub","acceptingIpFilterRule":null}',
  'iothub-connection-module-id': 'my-test-module-a',
  'iothub-enqueuedtime': '2021-07-13T22:08:09Z',
  'x-opt-sequence-number': '35',
  'x-opt-enqueued-time': '2021-07-13T22:08:09Z',
  'x-opt-offset': '21560',
  'traceparent': '00-4655608164bc48b985b42d39865f3834-ed6cf3697c86e7bd-01'
}

相关链接