python - 使用 python 应用程序将数据发送到 azure 事件中心
问题描述
我正在使用我的 python 应用程序向事件中心发送 JSON 转储。我的连接字符串的形式是
connection_string="端点=sb://xyz.servicebus.windows.net/;SharedAccessKeyName=abc;SharedAccessKey=pqr"
我得到以下回复
令牌放置完成,结果:0,状态:202,描述:b'Accepted',连接:xxxxxxxxx
但是我没有在eventhub中看到数据。我也没有收到任何错误。我的问题是正在发送的事件?如果事件发送成功,我们应该不会得到响应码 200 吗?
我的代码来自这个链接
from azure.eventhub import EventHubProducerClient, EventData
def send_event_data_batch(producer, data):
# Without specifying partition_id or partition_key
# the events will be distributed to available partitions via round-robin.
event_data_batch = producer.create_batch()
event_data_batch.add(EventData(data))
try:
producer.send_batch(event_data_batch)
except Exception as exp:
_LOG.info(type(exp).__name__)
_LOG.info(exp.args)
producer.close()
def send_data_to_event_hub(data):
producer = EventHubProducerClient.from_connection_string(
conn_str=connection_string,
eventhub_name="EVENT HUB NAME" )
with producer:
send_event_data_batch(producer, data)
producer.close()
解决方案
send() 方法如果成功则不返回任何内容 ( None
),如果不成功则引发家庭错误EventHubError
。“Token put complete with result: 0, status: 202, description: b'Accepted', connection:xxxxxxxxx”是建立连接的日志信息。
推荐阅读
- rust - 解决 rust 中需要相互引用的特征之间的循环依赖关系
- java - JVM关闭顺序和事务管理?
- database-design - 使用 Data Vault 建模 INFORMATION_SCHEMA
- r - 在 r 中对二元概率模型进行后测?
- java - 如何从 Java 中的 API 获取自定义数据
- odata - 使用 odata-core 将 sap:quickinfo 映射到生成的 Java 实体中
- c# - 从 C# 中的 Parquet 文件中读取前 100 行
- google-apps-script - 创建新的触发器问题
- python - 如何约束 Union 以使输入和输出类型匹配?
- html - 有没有办法从 url 中找到 iframe 链接?