Low Orbit Flux Logo 2 D

RabbitMQ How to Purge / Clear All Queues

There are situations where you may need to clear or purge all messages from a queue. Sometimes you might also want to do this for all queues. We are going to show you how you can do both of these things with RabbitMQ.

You can purge or clear a queue with the following command:

rabbitmqctl purge_queue queue1

Purge Queue from the Web UI

RabbitMQ How to Purge / Clear All Queues

Purging all queues is relatively easy.

First, compile a list of queues. You can edit this if you decide you don’t want to remove all queues.

rabbitmqadmin -f tsv -q list queues name > list1.txt

Second just loop over every item in the file and pass the value to the rabbitmqctl command.

for i in `cat list1.txt`; do rabbitmqctl purge_queue "$i"; done 

Extra Info

You may need to specify a user and password like this:

rabbitmqadmin --user guest 
 --password SecretPassword1 -f tsv -q list queues name > list1.txt

You can also create a list of queues using the rabbitmqctl command. The advantages of this are that you won’t need to have rabbitmqadmin installed and you won’t need to specify a password ( when one is setup ) to run on the same host ( at least I didn’t ). It does generate some extra lines of output which would need to be removed from the file.

rabbitmqctl list_queues name > list1.txt