Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I need to have a python client that can discover queues on a restarted RabbitMQ server exchange, and then start up a clients to resume consuming messages from each queue. How can I discover queues from some RabbitMQ compatible python api/library?

like image 221
rschramm Avatar asked Nov 26 '10 19:11

rschramm


People also ask

How do I list queues in RabbitMQ?

The rabbitmqctl command with the list_queues option can be used to list a virtual hosts queues. Or, the rabbitmqadmin list queues command can be used. Or, the curl command can be used. Which should produce something like this.

What is exchange and queue in RabbitMQ?

Exchanges are message routing agents, defined by the virtual host within RabbitMQ. An exchange is responsible for routing the messages to different queues with the help of header attributes, bindings, and routing keys. A binding is a "link" that you set up to bind a queue to an exchange.


1 Answers

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.

like image 139
IvanD Avatar answered Oct 19 '22 21:10

IvanD