1
votes

I have a subscription to a topic using filters in Azure Service Bus develop with Python 3.x and when I wait the information sent to that topic (information that pass the filter) I can not receive it.

I need to create a daemon that is always listening and that when I receive that information I send it to an internal service of my application, so the receiver is running in a thread inside a loop While True

The code I use to receive the messages is as follows:

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()

What I get when I run it is the next information:

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'

If I run the receiver out of the thread, this is the error message it shows (again when the timeout is skipped, which timeout I should delete because in a daemon that is waiting it can not skip). Basically, it is the same error:

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'

I do not receive the information I'm waiting and also skip a Service Bus timeout (which I have not programmed).

Can anybody help me? Microsoft's documentation does not help much, really.

Thanks in advance

UPDATE

I think that the problem is from Azure Service Bus and the subscriptions and filters. Actually, I have 23 filters and I think Azure Service Bus only works with 1 subscription :( But I'm not sure about this point.

1
What happens when you print msg? My guess is that you're not getting anything back from the Service Bus.Gaurav Mantri
Exactly, I don't have anything :( As you can see in the trace, the first line is the result of message: None :(jjmartinez
And I should receive messages (because I'm sending with other application, of course). Also, I have the same code develop with Java and I receive the messages that I'm waiting in Python.jjmartinez

1 Answers

1
votes

I tried to reproduce your issue successfully, then I discovered that it happended if there is no message in your topic.

So you need to check the value or type of msg.body whether be None or type(None) before decode the bytes of msg.body, as below.

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

Hope it helps.