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?
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With