Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure事件中心Python SDK_Python_Azure_Mqtt_Azure Iot Hub_Azure Eventhub - Fatal编程技术网

Azure事件中心Python SDK

Azure事件中心Python SDK,python,azure,mqtt,azure-iot-hub,azure-eventhub,Python,Azure,Mqtt,Azure Iot Hub,Azure Eventhub,任何人都可以解释如何使用python事件中心SDK使用“事件中心兼容名称”和“事件中心兼容端点”。SDK要求 # Address can be in either of these formats: # "amqps://<URL-encoded-SAS-policy>:<URL-encoded-SAS- # "key>@<mynamespace>.servicebus.windows.net/myeventhub" # "amqps://<mynam

任何人都可以解释如何使用python事件中心SDK使用“事件中心兼容名称”和“事件中心兼容端点”。SDK要求

# Address can be in either of these formats:
# "amqps://<URL-encoded-SAS-policy>:<URL-encoded-SAS- 
# "key>@<mynamespace>.servicebus.windows.net/myeventhub"
# "amqps://<mynamespace>.servicebus.windows.net/myeventhub"
ADDRESS = os.environ.get('EVENT_HUB_ADDRESS')

# SAS policy and key are not required if they are encoded in the URL
USER = os.environ.get('EVENT_HUB_SAS_POLICY')
KEY = os.environ.get('EVENT_HUB_SAS_KEY')
#地址可以采用以下格式之一:

#“amqps://:如果您希望使用最新的Azure Event Hub Python SDK从IoT Hub内置端点接收设备到云的消息,还有另一个选项,您可以参考以下代码:

import os
import sys
import logging
import time
from azure.eventhub import EventHubClient, Receiver, Offset

PARTITION = "0"

total = 0
last_sn = -1
last_offset = "-1"

client = EventHubClient.from_iothub_connection_string("{iot hub connection string}", debug=True)

try:
    receiver = client.add_receiver("$default", PARTITION, operation='/messages/events')
    client.run()
    start_time = time.time()
    for event_data in receiver.receive(timeout=100):
        last_offset = event_data.offset
        last_sn = event_data.sequence_number
        print("Received: {}, {}".format(last_offset, last_sn))
        total += 1

    end_time = time.time()
    client.stop()
    run_time = end_time - start_time
    print("Received {} messages in {} seconds".format(total, run_time))

except KeyboardInterrupt:
    pass
finally:
    client.stop()
我想如果没有 具体原因是,最好使用IoT Hub自己的特定Python客户端库来接收消息。

鉴于您提到了“事件中心兼容名称”和“事件中心兼容端点”,我假设您正在尝试连接到IoT Hub的事件中心兼容端点

使用此事件中心兼容名称
iothub-ehub-getstarted-99999-xxxxxxxxx
而此事件中心兼容端点
endpoint=sb://ihsuprodbyres999dednamespace.servicebus.windows.net/;SharedAccessKeyName=IoTubOwner;SharedAccessKey=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=

然后,事件中心地址看起来像这样:
amqps://ihsuprodbyres999dednamespace.servicebus.windows.net/iothub-ehub-getstarted-99999-xxxxxxxxxx

对于事件中心SAS_策略事件中心SAS_键值,您可以使用IoTubownwer服务作为SAS策略及其对应键。您可以在IoT中心的共享访问策略页面的门户中找到这些