Search code examples
pythonrabbitmqpython-multithreading

RabbitMQ: can both consuming and publishing be done in one thread?


can both consuming and publishing be done in one Python thread using RabbitMQ channels?


Solution

  • Actually this isn't a problem at all and you can do it quite easily with for example pika the problem is however that you'd have to stop the consuming since it's a blocking loop or do the producing during the consume of a message.

    Consuming and producing is a normal usecase, especially in pika since it isn't threadsafe, when for example you'd want to implement some form of filter on the messages, or, perhaps a smart router, which in turn will pass on the messages to another queue.