【发布时间】:2017-08-30 07:42:00
【问题描述】:
我使用Azure Service Bus 中的过滤器订阅了一个主题,使用Python 3.x 开发,当我等待发送到该主题的信息(通过过滤器的信息)时,我无法接收它。
我需要创建一个一直在监听的守护进程,当我收到该信息时,我会将其发送到我的应用程序的内部服务,因此接收器在循环内的线程中运行 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'
我没有收到我正在等待的信息,并且还跳过了服务总线超时(我没有编程)。
有人可以帮助我吗? Microsoft 的文档确实没有多大帮助。
提前致谢
更新
我认为问题出在 Azure 服务总线以及订阅和筛选器上。实际上,我有 23 个过滤器,我认为 Azure 服务总线仅适用于 1 个订阅 :( 但我不确定这一点。
【问题讨论】:
-
打印
msg时会发生什么?我的猜测是你没有从服务总线得到任何回报。 -
没错,我什么都没有 :( 正如您在跟踪中看到的那样,第一行是消息的结果:无 :(
-
我应该会收到消息(因为我是用其他应用程序发送的,当然)。此外,我使用 Java 开发了相同的代码,并且收到了我在 Python 中等待的消息。
标签: python-3.x azureservicebus azure-servicebus-queues azure-servicebus-topics