我安装了rabbitmqadmin,并且能够列出所有的交换机和队列。如何使用rabbitmqadmin或rabbitmqctl删除所有的队列。


当前回答

实际上管理插件和策略非常简单:

Goto管理控制台(localhost:15672) Goto管理选项卡 Goto Policies选项卡(在右侧) 添加政策 填充字段 虚拟主机:选择 名称:过期所有策略(稍后删除) 模式:. * 适用于:队列 定义:以值1到期(将类型从字符串更改为数字) 保存 签出队列选项卡 必须删除所有队列 不要忘记删除策略!!!!!!。

其他回答

如果你只想清除不空的队列(更快):

rabbitmqctl list_queues | awk '$2!=0 { print $1 }' | sed 's/Listing//' | xargs -L1 rabbitmqctl purge_queue

对我来说,清除一个队列(空队列和非空队列)需要2-3秒,所以遍历50个队列非常痛苦,而我只需要清除其中的10个队列(40/50是空队列)。

使用rabbitmqadmin,你可以用下面的一行程序删除它们:

rabbitmqadmin -f tsv -q list queues name | while read queue; do rabbitmqadmin -q delete queue name=${queue}; done

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

如果你没有安装rabbitmqadmin,尝试使用rabbitmqctl清除队列:

rabbitmqctl list_queues | awk '{print $1}' | xargs -L1 rabbitmqctl purge_queue . txt

试试这个:

 rabbitmqadmin list queues name | awk '{print $2}' | xargs -I qn rabbitmqadmin delete queue name=qn