How do I delete all messages from a single queue using the cli? I have the queue name and I want to clean it.
11 Answers
you can directly run this command
sudo rabbitmqctl purge_queue queue_name

- 2,281
- 1
- 11
- 10
-
18or, if you have a virtual host, do `rabbitmqctl purge_queue queue_name -p my_virt_host` – goat Jun 01 '16 at 15:49
-
4run sudo rabbitmqctl -h and check list of cammand listed by your current rabbitmq. if it is not there it means current version of rabbitmq does not support this feature. – Anurag jain Jun 07 '16 at 06:28
-
1This didn't work for me -- as soon as my consumer fired up, the queue was still full of tasks. – MuffintopBikini Aug 29 '17 at 22:58
-
This could have been implemented in either 3.5.4 or 3.6.0, based on https://github.com/rabbitmq/rabbitmq-server/pull/215 and https://www.rabbitmq.com/changelog.html . If you have an older version, rabbitmqadmin as per https://stackoverflow.com/a/18267342/272387 might help. – Richlv Oct 25 '17 at 11:44
-
1...and checking in https://github.com/rabbitmq/rabbitmq-server/releases/tag/rabbitmq_v3_5_4 , this feature appeared in 3.5.4. – Richlv Oct 26 '17 at 13:25
rabbitmqadmin is the perfect tool for this
rabbitmqadmin purge queue name=name_of_the_queue_to_be_purged

- 2,918
- 3
- 30
- 42
-
5I had a hard time finding the tool in my rabbitmq installation. I finally downloaded it from here: http://hg.rabbitmq.com/rabbitmq-management/raw-file/rabbitmq_v3_3_5/bin/rabbitmqadmin – Mukul M. Aug 30 '14 at 13:21
-
5If you have the management plugin already installed, you can downloaded it from `http://rabbitserver:15672/cli/` – morloch Jul 24 '15 at 08:13
-
RabbitMQ has 2 things under queue
- Delete
- Purge
Delete - will delete the queue
Purge - This will empty the queue (meaning removes messages from the queue but queue still exists)

- 569
- 6
- 13
To purge queue you can use following command (more information in API doc):
curl -i -u guest:guest -XDELETE http://localhost:15672/api/queues/vhost_name/queue_name/contents
-
Kind of scary how well this worked. Any way to protect against this happening unintentionally? Such as a config for production servers that disables this functionality to prevent accidental data loss? – Isaiah May 07 '18 at 23:06
-
1Yeah, the protection would be to delete the user "guest" using the "delete_user" command – Ocean Airdrop Oct 30 '18 at 16:00
RabbitMQ implements the Advanced Message Queuing Protocol (AMQP) so you can use generic tools for stuff like this.
On Debian/Ubuntu or similar system, do:
sudo apt-get install amqp-tools
amqp-delete-queue -q celery # where celery is the name of the queue to delete
amqp-declare-queue -d -q celery # where celery is the name of the queue to delete and the "-d" creates a durable/persistent queue
Edit 2022: Added amqp-declare-queue to the example

- 2,135
- 1
- 21
- 29
-
-
13This deletes the whole queue, doesn't just purge it. So the queue doesn't exist anymore and you have to re-initialize the empty queue afterwards. – krob Jun 30 '16 at 18:22
-
That's true. Luckily, ampq-tools also has a command to create a queue. The intention of this Answer was to show how we can achieve what the question asks using generic tools or when getting rabbitmqadmin isn't feasible. – benjaoming Oct 12 '22 at 13:13
IMPORTANT NOTE: This will delete all users and config.
ALERT !!
ALERT !!
I don't suggest this answer until unless you want to delete data from all of the queues, including users and configs. Just Reset it !!!
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl start_app

- 14,611
- 5
- 38
- 45
-
31
-
I used this as part of unit tests. e.g. I clear everything, then set it all up programmically via http://stackoverflow.com/questions/4545660/rabbitmq-creating-queues-and-bindings-from-a-command-line/25915568#25915568 then populate some messages and do black box testing to make sure messages went through. Works great for this purpose. :) – James Oravec Jun 30 '15 at 16:25
-
4zeroing your storage and reinstalling the OS also gets rid of the data; this is not what OP is asking – istepaniuk Jun 05 '19 at 14:58
In order to delete only messages from the queue use :
sudo rabbitmqctl --node <nodename> purge_queue <queue_name>
In order to delete a queue which is empty(--if-empty) or has no consumers(--if-unused) use :
sudo rabbitmqctl --node <nodename> delete_queue <queue_name> --if-empty
or
sudo rabbitmqctl --node <nodename> delete_queue <queue_name> --if-unused

- 876
- 11
- 10
I guess its late but for others reference, this can be done with pika
import pika
host_ip = #host ip
channel = pika.BlockingConnection(pika.ConnectionParameters(host_ip,
5672,
"/",
credentials=pika.PlainCredentials("username","pwd"))).channel()
print "deleting queue..", channel.queue_delete(queue=queue_name)

- 1,111
- 13
- 17
-
2hi @prajnavantha is pika has any method clear message only? (not delete queue) – Jade Han Jun 18 '18 at 04:02
In case you are using RabbitMQ with Docker your steps should be:
- Connect to container: docker exec -it your_container_id bash
- rabbitmqctl purge_queue Queue-1 (where Queue-1 is queue name)

- 344
- 3
- 5
-
Why would it be different if one would purge the queue from outside the docker container? Isn't the queue completely oblivious to **whom** (or rather **what**) is using it? I am not suggesting anything, I am just asking. – M.Ionut Aug 25 '21 at 07:22
I have successfully used ampq-purge
from amqp-utils to do this:
git clone https://github.com/dougbarth/amqp-utils.git
cd amqp-utils
# extracted from Rakefile
echo "source 'https://rubygems.org'
gem 'amqp', '~> 0.7.1'
gem 'trollop', '~> 1.16.2'
gem 'facets', '~> 2.9'
gem 'clio', '~> 0.3.0'
gem 'json', '~> 1.5'
gem 'heredoc_unindent', '~> 1.1.2'
gem 'msgpack', '~> 0.4.5'" > Gemfile
bundle install --path=$PWD/gems
export RUBYLIB=.
export GEM_HOME=$PWD/gems/ruby/1.9.1
ruby bin/amqp-purge -v -V /vhost -u user -p queue
# paste password at prompt

- 32,721
- 10
- 101
- 130
My rabbitmqclt
was an older version without purge_queue, and I did not have rabbitmqadmin
installed.
Our app runs on celery and it has this command that worked:
celery -A <app_name> -Q <queue_name> purge

- 1,182
- 12
- 12