我安装了rabbitmqadmin,并且能够列出所有的交换机和队列。如何使用rabbitmqadmin或rabbitmqctl删除所有的队列。
当前回答
另一个选项是删除与队列关联的vhost。这将删除与vhost关联的所有内容,因此请注意,但这很简单且快速。
注意:RabbitMQ团队会监控RabbitMQ用户的邮件列表,有时只在StackOverflow上回答问题。
其他回答
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
在Rabbit 3.7.10版本中,你可以以root权限运行以下命令:
rabbitmqctl list_queues | awk '{ print $1 }' | xargs -L1 rabbitmqctl delete_queue
如果你只想清除不空的队列(更快):
rabbitmqctl list_queues | awk '$2!=0 { print $1 }' | sed 's/Listing//' | xargs -L1 rabbitmqctl purge_queue
对我来说,清除一个队列(空队列和非空队列)需要2-3秒,所以遍历50个队列非常痛苦,而我只需要清除其中的10个队列(40/50是空队列)。
我尝试了上面的代码段,但我没有做任何流。
Sudo rabbitmqctl list_queues | awk '{print $1}' > queues.txt;对于$(cat queue .txt)中的行;执行sudo rabbitmqctl delete_queue "$line";完成了。
我生成一个包含所有队列名称的文件,并逐行循环删除它们。对于循环,当读取…不是为了我。它总是在第一个队列名处停止。
你可以这样使用rabbitmqctl eval:
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 ].'
上述操作将删除所有有名称的vhosts中的所有空队列 以“前缀-”开头。 你可以编辑变量IfUnused, IfEmpty, 和MatchRegex根据您的要求。