我安装了rabbitmqadmin,并且能够列出所有的交换机和队列。如何使用rabbitmqadmin或rabbitmqctl删除所有的队列。
当前回答
下面是一种使用PowerShell的方法。URL可能需要更新
$cred = Get-Credential
iwr -ContentType 'application/json' -Method Get -Credential $cred 'http://localhost:15672/api/queues' | % {
ConvertFrom-Json $_.Content } | % { $_ } | ? { $_.messages -gt 0} | % {
iwr -method DELETE -Credential $cred -uri $("http://localhost:15672/api/queues/{0}/{1}" -f [System.Web.HttpUtility]::UrlEncode($_.vhost), $_.name)
}
其他回答
如果安装rabbitmqadmin有问题,请先安装python。
类unix操作系统用户需要将rabbitmqadmin复制到PATH中的某个目录,例如/usr/local/bin。
Windows用户将需要确保Python在他们的PATH上,并调用rabbitmqadmin作为Python .exe rabbitmqadmin。
然后
浏览http://{hostname}:15672/cli/rabbitmqadmin进行下载。 进入包含的文件夹,然后以管理员权限运行cmd
列出队列 Python rabbitmqadmin列表队列。
删除队列 python rabbitmqadmin删除队列名称=队列名称
删除所有队列
1-声明政策
python rabbitmqadmin declare policy name='expire_all_policies' pattern=.* definition={\"expires\":1} apply-to=queues
2-删除策略
python rabbitmqadmin delete policy name='expire_all_policies'
如果你只想清除不空的队列(更快):
rabbitmqctl list_queues | awk '$2!=0 { print $1 }' | sed 's/Listing//' | xargs -L1 rabbitmqctl purge_queue
对我来说,清除一个队列(空队列和非空队列)需要2-3秒,所以遍历50个队列非常痛苦,而我只需要清除其中的10个队列(40/50是空队列)。
实际上管理插件和策略非常简单:
Goto管理控制台(localhost:15672) Goto管理选项卡 Goto Policies选项卡(在右侧) 添加政策 填充字段 虚拟主机:选择 名称:过期所有策略(稍后删除) 模式:. * 适用于:队列 定义:以值1到期(将类型从字符串更改为数字) 保存 签出队列选项卡 必须删除所有队列 不要忘记删除策略!!!!!!。
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,你可以用下面的一行程序删除它们:
rabbitmqadmin -f tsv -q list queues name | while read queue; do rabbitmqadmin -q delete queue name=${queue}; done