How to delete all queues in RabbitMQ
I recently had to do this for one of my older Django projects that uses Celery as I made the mistake of using the broker as the result backend.
Using "amqp" as the result backend is not recommended in production as this will create a queue for each task. I noticed I was getting a warning for the file descriptors in the RabbitMQ web management dashboard.
From the web management (available by installing the management plugin), you can delete these queues, but you can only delete them one-by-one. With over a thousand of them, this is just too time consuming.
Luckily, the management plugin also comes with a command line tool called rabbitmqadmin. Using this tool, you can then write a small script to delete all queues in one shot. You can actually even do this in one command line.
Here are the steps (tested on Ubuntu 16.04):
Copy over the "rabbitmqadmin" tool to /usr/local/bin
# Find the location where it's stored first >>> locate rabbitmqadmin # Copy from that location to /usr/local/bin >>> cp /path_to_rabbitmqadmin /usr/local/bin >>> cd /usr/local/bin >>> chmod 755 rabbitmqadmin
Execute the command below
>>> rabbitmqadmin --vhost=yourvhost --username=admin --password='yourpassword' -f tsv -q list queues name | while read queue; do rabbitmqadmin --vhost=yourvhost --username=admin --password='yourpassword' -q delete queue name=${queue}; done
Note to replace the value of --vhost, --username, and --password in the command with your vhost/credentials (don't forget to surround the values with single quotes in case they contain characters like "!" that could conflict with bash commands).
Credit goes to this StackOverflow post.
Tags: howto, devops, tech, software development, celery