简体   繁体   English

使用 python 应用程序将数据发送到 azure 事件中心

[英]Send data to azure event hub using python app

I'm sending a JSON dump to the event hub using my python app.我正在使用我的 python 应用程序将 JSON 转储发送到事件中心。 My connection string is of the form我的连接字符串的形式

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

I get the following response我得到以下回复

Token put complete with result: 0, status: 202, description: b'Accepted', connection:xxxxxxxxx令牌放置完成,结果:0,状态:202,描述:b'Accepted',连接:xxxxxxxxx

But I don't see the data in the eventhub.但是我在eventhub中没有看到数据。 I don't get any error as well.我也没有收到任何错误。 My question is the event being sent?我的问题是事件正在发送? If the event is successfully sent, should we not get a response code 200?如果事件发送成功,我们应该不会得到响应代码 200 吗?

My code is from this 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()

The send() method returns nothing ( None ) if it's successful, or raises an error of family EventHubError if it's not successful.如果成功, send() 方法不返回任何内容( None ),如果不成功则引发家庭EventHubError错误。 The "Token put complete with result: 0, status: 202, description: b'Accepted', connection:xxxxxxxxx" is logging information of building connections. “Token put complete with result: 0, status: 202, description: b'Accepted', connection:xxxxxxxxx”是建立连接的日志信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Python 将事件发送到 Azure 事件中心 - Send events to Azure event hub using Python 如何持续从证券交易所等网站获取数据并使用 python 将其发送到 azure 事件中心? - How to continuously fetch data from websites like Stock exchange and send it to azure event hub using python? 使用 python 在 Azure 事件中心收集 Websocket 流数据 - Collect Websocket streaming data in Azure Event Hub using python Azure 功能 Python | 将带有属性的 EventData 消息发送到事件中心 output - Azure Functions Python | Send EventData messages with properties to Event Hub output 如何在Python中使用amqp将消息发送到Azure事件中心 - How to send message to Azure event hub with amqp in python 使用 python 处理事件中心数据 - Processing event hub data using python 无法将我的模拟设备连接到Azure IoT中心以使用Python发送数据 - Failing to connect my simulated device to azure IoT hub to send the data using Python 使用QPID和Python从Azure事件中心接收 - Receiving from Azure Event Hub using QPID and Python 使用 Python 使用来自 Azure 事件中心的消息? - Consuming messages from an Azure Event Hub using Python? Python Azure 事件中心使用事件属性 - Python Azure Event Hub Consume Event Properties
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM