python - RabbitMQ non-blocking consumer -


I am using RabbitMQ in Python to manage multiple queues between a manufacturer and multiple users. In the example RabbitMQ website (), consumers are blocking. This means that they stop (stop) on start_consuming and every time a new "work" callback function executed in the queue

My question is:. How can I implement my consumer in a way that is still waiting for tasks (hence, callback function is called new things every time in the queue) but at the same time it can execute other work / code is.

Thanks to Hugo

for receiver

 < Code> Import Pica Messages = [] Connection = pika.BlockingConnection (ConeConnectionParameters ('localhost')) channel = connection.channel () channel.queue_declare (queue = 'message') DEF callback (ch, method, property, Message): print (messages) messages.append (message) channel.basic_consume (callback, queue = 'message', no_ack = true)  

and

     

E> import threading import pica import time messages = [] def recieve_messages (): connection = pika.BlockingConnection (pika.ConnectionParameters ('localhost')) channel = connection.channel () channel.queue_declare (queue = ' Hello ') DEF Callback (ch, method, property, body): messages.append (body) channel.basic_consume (callback, queue =' hello ', no_ack = true) # channel.start_consuming () mq_recieve_thread = threading.Thread (target = Channel.start_consuming) mq_recieve_thread.start () Recieve_messages () While correct: Print message time.sleep (1)


Comments