我訂閱了使用Azure Service Bus
中的過濾器的主題並使用Python 3.x
開發,當我等待發送到該主題的信息(通過過濾器的信息)時,我無法接收它。在Azure服務總線上接收有關主題訂閱的信息
我需要創建一個守護進程總是聽,當我收到信息,我把它發送到我的應用程序的內部服務,所以接收機在一個線程中運行循環While True
裏面的代碼我用它來接收消息如下:
while True:
msg = bus_service.receive_subscription_message(topic_name, subscription_name, peek_lock=True)
print('Mensaje Recibido-->',msg.body)
data = msg.body
send_MyApp(data.decode("utf-8"))
msg.delete()
我能得到什麼,當我運行它是下一個信息:
Message --> None
Exception in thread Thread-1:
Traceback (most recent call last):
File "..\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "..\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "../Python/ServiceBusSuscription/receive_subscription.py", line 19, in receive_subscription
send_MyApp(data.decode("utf-8"))
AttributeError: 'NoneType' object has no attribute 'decode'
如果我將接收器從線程中運行,這是它顯示的錯誤消息(當超時被跳過時,我應該刪除哪個超時,因爲在等待它的守護進程中不能跳過)。基本上,這是同樣的錯誤:
Traceback (most recent call last):
File "../Python/ServiceBusSuscription/receive_subscription.py", line 76, in <module>
main()
File "../Python/ServiceBusSuscription/receive_subscription.py", line 72, in main
demo(bus_service)
File "../Python/ServiceBusSuscription//receive_subscription.py", line 25, in demo
print(msg.body.decode("utf-8"))
AttributeError: 'NoneType' object has no attribute 'decode'
我沒有收到我在等待的信息,並且還跳過一個服務總線超時(我還沒有編程)。
任何人都可以幫助我嗎?微軟的文檔並沒有太大幫助。
在此先感謝
UPDATE
我認爲這個問題是從Azure的服務總線和訂閱和過濾器。其實,我有23個過濾器,我認爲Azure服務總線只能用於1訂閱:(但我不確定這一點。
當你打印'msg'時會發生什麼?我的猜測是你沒有從服務總線獲得任何回報。 –
確切的說,我沒有任何東西:(正如你可以在跟蹤中看到的,第一行是消息的結果:無:( – jjmartinez
)我應該收到消息(因爲我使用其他應用程序發送消息,當然)另外,我使用Java開發了相同的代碼,並收到了我在Python中等待的消息 – jjmartinez