【发布时间】:2020-10-01 09:56:25
【问题描述】:
我正在尝试使用 pythonEventHubProducerClient 库将带有正文和属性部分的 JSON 消息发送到 Azure EventHub,但目前无法包含属性部分。这是与此处提出的问题类似的问题,但是该修复对我不起作用:How to send Properties details in EventHub message using python?
我使用的代码如下:
eventhubConnectionString = "example connection string"
eventhubName = "example eventhub name"
body = '{"ExampleBody":"ExampleValue"}'
properties = {"ExampleProperty":"ExampleValue"}
async def send_message(eventhubConnectionString, eventhubName, body, properties):
producer = EventHubProducerClient.from_connection_string(conn_str=eventhubConnectionString, eventhub_name=eventhubName)
async with producer:
event_data_batch = await producer.create_batch()
event = EventData(body)
event.application_properties = properties
event_data_batch.add(event)
await producer.send_batch(event_data_batch)
运行时,代码不会产生任何错误,但是从 eventthub 读取消息时,消息中包含的属性不存在。有谁知道如何正确地将属性附加到消息中?任何帮助将不胜感激!
【问题讨论】:
标签: python json azure azure-eventhub