Delete all the queues from RabbitMQ?

167,790

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
Share:
167,790

Related videos on Youtube

Cory
Author by

Cory

Located in San Diego, CA.

Updated on January 21, 2022

Comments

  • Cory
    Cory over 2 years

    I installed rabbitmqadmin and was able to list all the exchanges and queues. How can I use rabbitmqadmin or rabbitmqctl to delete all the queues.

  • Guillaume Vincent
    Guillaume Vincent over 10 years
    to see all pending tasks in rabbitmq: rabbitmqctl list_queues name messages messages_ready \ messages_unacknowledged
  • Robert Ross
    Robert Ross about 10 years
    I receive this when running it: head: illegal line count -- -1
  • thoufek
    thoufek about 10 years
    Be 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
    lukiffer almost 10 years
    Apologies @smartnut007, I've clarified the second portion of the answer with a disclaimer.
  • au_stan
    au_stan almost 10 years
    just grabbing the empty queues. rabbitmqctl list_queues | grep 0 | awk '{print $1}' | xargs -I qn rabbitmqadmin delete queue name=qn
  • Devy
    Devy almost 10 years
    @austin 's receipt works perfectly. Just make sure you have root privilege before you run that.
  • Gerd Busker
    Gerd Busker almost 10 years
    The "head -n-1" should be either "head -1" or "head -n 1"
  • Peter Goodman
    Peter Goodman about 9 years
    Note, this only deletes non-empty queues. Remove the -gt clause to delete all queues
  • woot
    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
    Hendy Irawan over 8 years
    including durable queues? I don't think so. I'll qualify your answer.
  • eracube
    eracube over 8 years
    No, durable queues cannot be deleted by stopping the server. They can be deleted from RabbitMQ Management web interface under queues.
  • sudo
    sudo almost 8 years
    I'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
    sudo almost 8 years
    BTW, to get rabbitmqadmin, you need to go to http://yourhost:15672/cli/ and download it.
  • NuSkooler
    NuSkooler over 7 years
    Perfect for when rabbitmqadmin is not accessible.
  • Mark Edington
    Mark Edington almost 7 years
    Is 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
    Mark Edington almost 7 years
    This 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 be rabbitmqadmin list queues name | awk '!/--|name/ {print $2}' | xargs -I qn rabbitmqadmin delete queue name=qn to fix it.
  • Zeeshan Ajmal
    Zeeshan Ajmal over 6 years
    @lukiffer i know it's a bit dumb question, but where one should run these commands ??
  • lukiffer
    lukiffer over 6 years
    @ZeeshanAjmal you can run them from whatever shell you want, so long as they're in your PATH.
  • Rolice
    Rolice over 6 years
    There is no delete_queue nor purge_queue commands in rabbitmqctl. I would like to purge a lot of queues that seem to be automatically generated and I would not like to install extra software like rabbitmqadmin...
  • Rolice
    Rolice over 6 years
    Actually yes, this helped me and all about 4500 automatically generated queues are gone. It seems that these were non-durable ones. Thanks!
  • Roman Susi
    Roman Susi over 6 years
    rabbitmqctl purge_queue worked here manually. I only needed to add -p <virtual-host>
  • Arpit Solanki
    Arpit Solanki about 6 years
    seeing 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
    Scott Leonard over 5 years
    rabbitmqadmin list queues name | awk {'print$2'} | egrep [^name] | xargs -I qname rabbitmqadmin delete queue name=qname
  • Logans
    Logans over 5 years
    In 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
    Mathias over 5 years
    select "Number" at Definition. Does not work with default ("String")
  • Wiktor Zychla
    Wiktor Zychla over 5 years
    Great 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
    acidburn23 about 5 years
    Very clean solution, without the need to play around the instance SSH.
  • TerrenceSun
    TerrenceSun almost 5 years
    I found this much faster than list_queues
  • gelonida
    gelonida over 4 years
    Pity nobody explains how to install management plugin and policies
  • gelonida
    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
    Richard Dunn over 4 years
    Contrary to what @Rolice stated above, both delete_queue and purge_queue are available in rabbitmqctl and I've just run them successfully. Perhaps you're on an old version.
  • Rolice
    Rolice over 4 years
    Good to hear that, these could have been added recently.
  • Jaded
    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 have guid string in them, and the policy have no effect.
  • Mathias
    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
    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
    Mohammad Naseri over 3 years
    Hmm, 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
    ckatsara about 3 years
    Has 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
    ckv over 2 years
    I 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
    paivaric over 2 years
    this is the fastest way
  • kuldeep
    kuldeep about 2 years
    how can i delete all the exchanges at once ?
  • Sudhanshu Mishra
    Sudhanshu Mishra about 2 years
    You may have to use -H to specify host and -u and -p parameters to specify the credentials to connect to server