Delete all the queues from RabbitMQ?

2020-02-16 05:42发布

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.

23条回答
疯言疯语
2楼-- · 2020-02-16 05:53

I tried the above pieces of code but I did not do any streaming.

sudo rabbitmqctl list_queues | awk '{print $1}' > queues.txt; for line in $(cat queues.txt); do sudo rabbitmqctl delete_queue "$line"; done.

I generate a file that contains all the queue names and loops through it line by line to the delete them. For the loops, while read ... did not do it for me. It was always stopping at the first queue name.

查看更多
贪生不怕死
3楼-- · 2020-02-16 05:54

You can use rabbitmqctl eval as below:

rabbitmqctl eval 'IfUnused = false, IfEmpty = true, MatchRegex = 
<<"^prefix-">>, [rabbit_amqqueue:delete(Q, IfUnused, IfEmpty) || Q <- 
rabbit_amqqueue:list(), re:run(element(4, element(2, Q)), MatchRegex) 
=/= nomatch ].' 

The above will delete all empty queues in all vhosts that have a name beginning with "prefix-". You can edit the variables IfUnused, IfEmpty, and MatchRegex as per your requirement.

查看更多
神经病院院长
4楼-- · 2020-02-16 05:54

Okay, important qualifier for this answer: The question does ask to use either rabbitmqctl OR rabbitmqadmin to solve this, my answer needed to use both. Also, note that this was tested on MacOS 10.12.6 and the versions of the rabbitmqctl and rabbitmqadmin that are installed when installing rabbitmq with Homebrew and which is identified with brew list --versions as rabbitmq 3.7.0

rabbitmqctl list_queues -p <VIRTUAL_HOSTNAME> name | sed 1,2d | xargs -I qname rabbitmqadmin --vhost <VIRTUAL_HOSTNAME> delete queue name=qname

查看更多
Root(大扎)
5楼-- · 2020-02-16 06:01

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
查看更多
爷的心禁止访问
6楼-- · 2020-02-16 06:02

There's a way to remove all queues and exchanges without scripts and full reset. You can just delete and re-create a virtual host from admin interface. This will work even for vhost /.

The only thing you'll need to restore is permissions for the newly created vhost.

查看更多
够拽才男人
7楼-- · 2020-02-16 06:03
rabbitmqadmin list queues|awk 'NR>3{print $4}'|head -n-1|xargs -I qname rabbitmqadmin delete queue name=qname
查看更多
登录 后发表回答