RabbitMQ How to Delete Single, Multiple, or All Queues
Once you have been using RabbitMQ for a little while you will probably find that you want to be able to clean things up a bit. It is helpful to be able to delete any queues that you’ve defined. You also may have a lot of queues which may have been generated programmatically. If you have hundreds or thousands you probably won’t want to delete them by hand. You will need a way to delete all queues in one shot.
Either of these commands can be used to delete a queue in RabbitMQ:
rabbitmqctl delete_queue queue1 rabbitmqadmin delete queue name=queue1
If you need to find a particular queue, this command will give you a list of them:
rabbitmqctl list_queues name
How to Delete All Queues in RabbitMQ
If you want to delete multiple queues you can use a for loop. In this example we delete three queues named: queue1, queue2, and queue3.
for i in queue1 queue2 queue3; do rabbitmqadmin -q delete queue name="$i"; done
In RabbitMQ you can delete all queues with these two steps:
- Generate a list of queues
- Loop over the queues in the list
First you will want to generate a list of all queues and write it to a file like this:
rabbitmqadmin -f tsv -q list queues name > list1.txt
You may need to specify a user and password like this:
rabbitmqadmin --user guest --password SecretPassword1 -f tsv -q list queues name > list1.txt
Next you can use a for loop to loop over every queue in this file and delete each one at a time.
for i in `cat list1.txt`; do rabbitmqadmin -q delete queue name="$i"; done
If you want a bit more control over which queues are removed you can edit the list1.txt file before you run the loop to actually delete them. You can also specify a user and password for this command like this:
for i in `cat list1.txt`; do rabbitmqadmin --user guest --password SecretPassword1 -q delete queue name="$i"; done
rabbitmqctl vs rabbitmqadmin
If you don’t have the rabbitmqadmin command you can install it by downloading from the web GUI after installing the RabbitMQ management plugin - see HERE.
Note that you could use the rabbitmqctl command to create your list of queues but you would need to remove the first few lines of the file because the command outputs extra information at the beginning.
rabbitmqctl list_queues name > list1.txt
You can also apparently use a command like this but I haven’t tested it:
curl -i -XDELETE https://USERNAME:PASSWORD@HOST/api/queues/rdkfegbx/QUEUE_NAME
Another option would be to create a policy that has an auto expire rule. The policy could be configured to match the queues that you want to remove. I haven’t tested this method either.