【问题标题】:Send data to azure event hub using python app使用 python 应用程序将数据发送到 azure 事件中心
【发布时间】:2020-07-13 15:45:35
【问题描述】:

我正在使用我的 python 应用程序向事件中心发送 JSON 转储。 我的连接字符串的形式是

connection_string="Endpoint=sb://xyz.servicebus.windows.net/;SharedAccessKeyName=abc;SharedAccessKey=pqr"

我收到以下回复

令牌放置完成,结果:0,状态:202,描述:b'Accepted',连接:xxxxxxxxx

但我没有在 eventthub 中看到数据。我也没有收到任何错误。我的问题是正在发送的事件?如果事件发送成功,我们应该不会得到响应码 200?

我的代码来自这个link

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()

【问题讨论】:

  • 如何检查数据不在eventthub中?并让我们知道您使用的是哪个版本的 sdk。
  • 代码中的响应是从哪里得到的?

标签: python azure message-queue azure-eventhub


【解决方案1】:

如果成功,send() 方法不返回任何内容 (None),如果不成功,则引发家庭错误EventHubError。 “Token put complete with result: 0, status: 202, description: b'Accepted', connection:xxxxxxxxx”是建立连接的日志信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-12
    • 1970-01-01
    • 2019-11-23
    相关资源
    最近更新 更多