【问题标题】:Python Azure Service Bus Identify sending devicePython Azure 服务总线识别发送设备
【发布时间】:2023-03-11 12:23:02
【问题描述】:

我想监控来自我的设备的遥测数据,并在特定顺序的消息到达时发送并通知我。

我可以使用事件总线 SDK 执行此操作,但我需要连接到所有分区,因为我不知道消息将到达哪个分区,并且假设随着更多设备的连接,分区号会增加,这似乎很慢而且很麻烦.

ReadMessage = True
try:
    timeout = time.time() + 60 #60second timer
    while ReadMessage and time.time() < timeout:
        for key in receivers:
            receive = receivers[key] #list of client objects to different partitions
            for event_data in receive.receive(timeout=1):
                meta = event_data.application_properties
                DevId = b'iothub-connection-device-id'
                messageType = b'messageType'
                currentDevice = event_data.message.annotations[DevId].decode('UTF-8')
                output_dict = event_data.body_as_json()
                if meta:
                    new_list = { key.decode(): val.decode() for key, val in meta.items() }
                    for key, val in new_list.items():
                        if key == 'messageType' and val == 'Message_I_Want'):
                            ReadMessage = False
                            #add to my list  device-id and message_i_want
                            break
        time.sleep(0.01)

    return #list of messages and deviceids
except Exception as ex:
    print ( "Unexpected error {0}" % ex )
    return  

我尝试使用 QueueClient 监听消息路由端点 get_receiver()。我可以看到进来的消息,但我无法确定是什么设备发送了消息。理想情况下,这将是一种更快的方法,因为我只需要打开连接。

所以我想问题是可以从服务总线获取设备 ID 吗?

谢谢

【问题讨论】:

  • 谢谢安德里亚,错过了那个。 :)

标签: python azure-eventhub azure-servicebus-queues


【解决方案1】:

好吧,我没有解决服务总线问题,但我确实通过使用异步任务使事件中心功能更快。

【讨论】:

    猜你喜欢
    • 2021-09-01
    • 2014-10-20
    • 2012-08-28
    • 1970-01-01
    • 1970-01-01
    • 2021-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多