Search code examples
pythonqueuerabbitmqamqppika

How to subscribe consumer to N number of unknown queues?


I'm trying to understand how to do this:

Some producers creates N number of queues ( lets say foo.1 foo.2 foo.3 ). Than I have one consumer on another part of the Rabbit that needs to get messages from all N (in my example 3 ) queues. I know I can do something like this:

(method_frame, header_frame, body) = self.channel.basic_get(queue='foo.1', no_ack=False)
(method_frame, header_frame, body) = self.channel.basic_get(queue='foo.2', no_ack=False)
(method_frame, header_frame, body) = self.channel.basic_get(queue='foo.3', no_ack=False)

But what if my consumer doesn't know the names, what I would really like to do is something like:

(method_frame, header_frame, body) = self.channel.basic_get(queue='foo.*', no_ack=False)

Solution

  • The RabbitMQ admin interface/api will have access to all of the queues on the server. There is an easy to use Python client PyRabbit that will let you get_queues. From there you can do whatever filtering you require.