Delete all the queues from RabbitMQ?
Solution 1
First, list your queues:
rabbitmqadmin list queues name
Then from the list, you'll need to manually delete them one by one:
rabbitmqadmin delete queue name='queuename'
Because of the output format, doesn't appear you can grep the response from list queues
. Alternatively, if you're just looking for a way to clear everything (read: reset all settings, returning the installation to a default state), use:
rabbitmqctl stop_app
rabbitmqctl reset # Be sure you really want to do this!
rabbitmqctl start_app
Solution 2
Actually super easy with management plugin and policies:
-
Goto Management Console (localhost:15672)
-
Goto Admin tab
-
Goto Policies tab(on the right side)
-
Add Policy
-
Fill Fields
- Virtual Host: Select
- Name: Expire All Policies(Delete Later)
- Pattern: .*
- Apply to: Queues
- Definition: expires with value 1 (change type from String to Number)
-
Save
-
Checkout Queues tab again
-
All Queues must be deleted
-
And don't forget to remove policy!!!!!!.
Solution 3
With rabbitmqadmin
you can remove them with this one-liner:
rabbitmqadmin -f tsv -q list queues name | while read queue; do rabbitmqadmin -q delete queue name=${queue}; done
Solution 4
In Rabbit version 3.7.10 you can run below command with root permission:
rabbitmqctl list_queues | awk '{ print $1 }' | xargs -L1 rabbitmqctl delete_queue
Solution 5
Try this:
rabbitmqadmin list queues name | awk '{print $2}' | xargs -I qn rabbitmqadmin delete queue name=qn
Related videos on Youtube
Comments
-
Cory over 2 years
I installed
rabbitmqadmin
and was able to list all the exchanges and queues. How can I userabbitmqadmin
orrabbitmqctl
to delete all the queues. -
Guillaume Vincent over 10 yearsto see all pending tasks in rabbitmq:
rabbitmqctl list_queues name messages messages_ready \ messages_unacknowledged
-
Robert Ross about 10 yearsI receive this when running it: head: illegal line count -- -1
-
thoufek about 10 yearsBe aware that "rabbitmqctl reset" will reset everything back to the "factory settings". Any RabbitMQ users, virtual hosts, etc, that you have created will be blown away.
-
lukiffer almost 10 yearsApologies @smartnut007, I've clarified the second portion of the answer with a disclaimer.
-
au_stan almost 10 yearsjust grabbing the empty queues.
rabbitmqctl list_queues | grep 0 | awk '{print $1}' | xargs -I qn rabbitmqadmin delete queue name=qn
-
Devy almost 10 years@austin 's receipt works perfectly. Just make sure you have root privilege before you run that.
-
Gerd Busker almost 10 yearsThe "head -n-1" should be either "head -1" or "head -n 1"
-
Peter Goodman about 9 yearsNote, this only deletes non-empty queues. Remove the -gt clause to delete all queues
-
woot over 8 years@au_stan That will delete all queues with a 0 in the name or the count. Might want to do
grep $'\t0'
or something. -
Hendy Irawan over 8 yearsincluding durable queues? I don't think so. I'll qualify your answer.
-
eracube over 8 yearsNo, durable queues cannot be deleted by stopping the server. They can be deleted from RabbitMQ Management web interface under queues.
-
sudo almost 8 yearsI've tried like 10 different answers, and this is the ONLY thing that has actually worked to delete queues without killing all my other settings. Thanks! I can't believe rabbitmqctl doesn't just have a "drop all queues" command.
-
sudo almost 8 yearsBTW, to get rabbitmqadmin, you need to go to
http://yourhost:15672/cli/
and download it. -
NuSkooler over 7 yearsPerfect for when
rabbitmqadmin
is not accessible. -
Mark Edington almost 7 yearsIs the rabbitmqctl "reset" flavor supposed to be compatible with rabbitmq installed via Homebrew? Didn't seem to work work for me. I ended up using one of the one liner answers.
-
Mark Edington almost 7 yearsThis worked for me, but also showed
*** Not found: /api/queues/%2F/name
because the output is a ASCII table with a "name" column. I tweaked the command to berabbitmqadmin list queues name | awk '!/--|name/ {print $2}' | xargs -I qn rabbitmqadmin delete queue name=qn
to fix it. -
Zeeshan Ajmal over 6 years@lukiffer i know it's a bit dumb question, but where one should run these commands ??
-
lukiffer over 6 years@ZeeshanAjmal you can run them from whatever shell you want, so long as they're in your
PATH
. -
Rolice over 6 yearsThere is no
delete_queue
norpurge_queue
commands inrabbitmqctl
. I would like to purge a lot of queues that seem to be automatically generated and I would not like to install extra software likerabbitmqadmin
... -
Rolice over 6 yearsActually yes, this helped me and all about 4500 automatically generated queues are gone. It seems that these were non-durable ones. Thanks!
-
Roman Susi over 6 years
rabbitmqctl purge_queue
worked here manually. I only needed to add -p <virtual-host> -
Arpit Solanki about 6 yearsseeing answers below this answer seems like a horrible idea. Why would I want to return my all settings to default just because I want to remove some queues.
-
Scott Leonard over 5 years
rabbitmqadmin list queues name | awk {'print$2'} | egrep [^name] | xargs -I qname rabbitmqadmin delete queue name=qname
-
Logans over 5 yearsIn my case queues are prefixed with keyword by which I can simply use
egrep
, so my command will look like this:rabbitmqadmin -f tsv -q list queues name | egrep "%search word%" | while read queue; do rabbitmqadmin -q delete queue name=${queue}; done
-
Mathias over 5 yearsselect "Number" at Definition. Does not work with default ("String")
-
Wiktor Zychla over 5 yearsGreat answer, actually made up my day. If you select "Exchanges and Queues" from the list, you could easily delete both Queues and Exchanges. I wish this could be the accepted answer.
-
acidburn23 about 5 yearsVery clean solution, without the need to play around the instance SSH.
-
TerrenceSun almost 5 yearsI found this much faster than list_queues
-
gelonida over 4 yearsPity nobody explains how to install management plugin and policies
-
gelonida over 4 years@MesutA. Thanks a lot. I think it's good to have this link in this article. It might be even better to add it to the answer, as comments might be purged. But I have now at least this info
-
Richard Dunn over 4 yearsContrary to what @Rolice stated above, both
delete_queue
andpurge_queue
are available inrabbitmqctl
and I've just run them successfully. Perhaps you're on an old version. -
Rolice over 4 yearsGood to hear that, these could have been added recently.
-
Jaded almost 4 years@Mesut A. @Mathias Is there any particular reason this does not work for me in 3.8.3? I'm using
.*guid.*
pattern to delete only exchanges/queues that haveguid
string in them, and the policy have no effect. -
Mathias almost 4 years@Jaded Number vs String was for the definition field, not for pattern. An older version of this answer did not contain the information to change the type from string to number.
-
Jaded almost 4 years@Mathias Number vs String for definition is not the case for underlying RabbitMQ version because they've added validator to value field that does not give you ability to add expires = "1", only expires = 1 (Number). To expand on the problem, what I've noticed after adding this policy, it appeared in the "features" column for target exchange ( "D", "ha-all", "NameOfMyPolicy") once (?).
-
Mohammad Naseri over 3 yearsHmm, I have ran it on Unix based OS and it works successfully, just make sure the result that passed to xargs command is ok.
-
ckatsara about 3 yearsHas anyone tried this solution with RabbitMQ v3.8.2 or higher? I seem to be running into some undefined Erlang error. Maybe the solution needs to be updated to reflect newer versions?
-
ckv over 2 yearsI tried similar command as above but get a syntax error before ^ Below is my command. kubectl exec -n kayaks svc/rabbitmq-ha -- rabbitmqctl --vhost=AM-Dev eval 'IfUnused = false, IfEmpty = true, MatchRegex = <<"^WOMSProvisioningSubscrptionQueue_platform-">>, [rabbit_amqqueue:delete(Q, IfUnused, IfEmpty) || Q <- rabbit_amqqueue:list(), re:run(element(4, element(2, Q)), MatchRegex) =/= nomatch ].'
-
paivaric over 2 yearsthis is the fastest way
-
kuldeep about 2 yearshow can i delete all the exchanges at once ?
-
Sudhanshu Mishra about 2 yearsYou may have to use -H to specify host and -u and -p parameters to specify the credentials to connect to server