Python user Kombu not notified about rabbitmq message (queue.get really works)

If I run the following code, the callback (test) passed to consumer never starts.

However, if I follow the rabbitmq GUI, I see that the message is being retrieved (but not acknowledged). Thus, it seems that the consumer is receiving the message, but not transmitting it to my callback. If I set no_ack to true, the message just disappears from the queue, again not calling the callback.

hn = "..." usr = "..." pwd = "..." vh = "/" port = 5672 rkey = "some.routing.key" qname = "some-queue-name" exchangeName = "MyExchange" connection = BrokerConnection(hostname=hn, userid=usr, password=pwd, virtual_host=vh, port=port) connection.connect() ch = connection.channel() # Create & the exchange exchange = Exchange(name=exchangeName, type="topic", channel=ch, durable=True) exchange.declare() # Temporary channel ch = connection.channel() # Create the queue to feed from balq = Queue(name=qname, exchange=exchange, durable=True, auto_delete=False, channel=ch, routing_key=rkey) # Declare it on the server balq.declare(); def test(b,m): print '** Message Arrived **' # Create a consumer consumer = Consumer(channel=connection.channel(), queues=balq, auto_declare=False, callbacks = [test] ) # register it on the server consumer.consume(no_ack=False); print 'Waiting for messages' while(True): pass 

However, the following code works correctly (I can successfully receive and acknowledge the message):

 m = balq.get(no_ack=False) m.ack() print m 

But the whole point is to remain asynchronous. So something should be wrong with my callback.

+4
source share
1 answer

Causes its simple mistake. Adding

 connection.drain_events() 

messages for the while loop occur.

+5
source

Source: https://habr.com/ru/post/1342860/


All Articles