【发布时间】: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