Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.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
Python 3.x 在Azure服务总线上接收有关主题订阅的信息_Python 3.x_Azureservicebus_Azure Servicebus Queues_Azure Servicebus Topics - Fatal编程技术网

Python 3.x 在Azure服务总线上接收有关主题订阅的信息

Python 3.x 在Azure服务总线上接收有关主题订阅的信息,python-3.x,azureservicebus,azure-servicebus-queues,azure-servicebus-topics,Python 3.x,Azureservicebus,Azure Servicebus Queues,Azure Servicebus Topics,我在Azure Service Busdevelop withPython 3.x中使用过滤器订阅了一个主题,当我等待发送到该主题的信息(通过过滤器的信息)时,我无法接收它 我需要创建一个始终在侦听的守护进程,当我接收到该信息时,我会将其发送到我的应用程序的内部服务,以便接收方在循环中的线程中运行,而True 我用来接收信息的代码如下: while True: msg = bus_service.receive_subscription_message(topic_name, subsc

我在
Azure Service Bus
develop with
Python 3.x
中使用过滤器订阅了一个主题,当我等待发送到该主题的信息(通过过滤器的信息)时,我无法接收它

我需要创建一个始终在侦听的守护进程,当我接收到该信息时,我会将其发送到我的应用程序的内部服务,以便接收方在循环
中的线程中运行,而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'
回溯(最近一次呼叫最后一次):
文件“./Python/servicebusscription/receive_subscription.py”,第76行,在
main()
文件“./Python/servicebussubscription/receive_subscription.py”,第72行,主目录
演示(巴士服务)
演示中第25行的文件“./Python/servicebusscription//receive_subscription.py”
打印(消息正文解码(“utf-8”))
AttributeError:“非类型”对象没有属性“解码”
我没有收到正在等待的信息,也跳过了服务总线超时(我没有编程)

有人能帮我吗?事实上,微软的文档帮助不大

提前谢谢

更新


我认为问题在于Azure服务总线以及订阅和过滤器。事实上,我有23个过滤器,我认为Azure Service Bus只适用于1个订阅:(但我不确定这一点。

我试图成功复制您的问题,然后我发现如果您的主题中没有消息,就会发生

因此,在解码
msg.body
的字节之前,您需要检查
msg.body
的值或类型是
None
还是
type(None)
,如下所示

data = msg.body
if data != None: 
# Or if type(data) == type(b''):
    send_MyApp(data.decode("utf-8"))
    msg.delete()
else:
    ...

希望有帮助。

当你打印
msg
时会发生什么?我猜你没有从服务总线上得到任何东西。确切地说,我没有任何东西:(正如你在跟踪中看到的,第一行是message:None的结果:(我应该收到消息(当然,因为我是用其他应用程序发送的)。此外,我使用Java开发了相同的代码,收到了Python中等待的消息。我认为您的答案是正确的,因为我认为问题在于Azure Service Bus中的订阅和筛选器。我将更新该问题,并将您的建议添加到我的代码中,谢谢!只有一个问题需要回答“if data==None”或“if data!=None”?@jjmartinez
if data!=None:
。对不起,我弄错了。我已经更新了我的邮政编码。