How can I list or discover queues on a RabbitMQ exchange using python?

There does not seem to be a direct AMQP-way to manage the server but there is a way you can do it from Python. I would recommend using a subprocess module combined with the rabbitmqctl command to check the status of the queues.

I am assuming that you are running this on Linux. From a command line, running:

rabbitmqctl list_queues

will result in:

Listing queues ...
pings   0
receptions      0
shoveled        0
test1   55199
...done.

(well, it did in my case due to my specific queues)

In your code, use this code to get output of rabbitmqctl:

import subprocess

proc = subprocess.Popen("/usr/sbin/rabbitmqctl list_queues", shell=True, stdout=subprocess.PIPE)
stdout_value = proc.communicate()[0]
print stdout_value

Then, just come up with your own code to parse stdout_value for your own use.

Leave a Comment