我安装了rabbitmqadmin,并且能够列出所有的交换机和队列。如何使用rabbitmqadmin或rabbitmqctl删除所有的队列。
当前回答
如https://stackoverflow.com/a/52002145/3278855
要实现自动化,可以使用curl:
curl -X PUT --data '{"pattern":".*","apply-to":"all","definition":{"expires":1},"priority":0}' -u guest:guest 'http://localhost:15672/api/policies/%2f/clear' && \
curl -X DELETE -u guest:guest 'http://localhost:15672/api/policies/%2f/clear'
请注意%2f是默认的v主机名(/),guest:guest是登录名:密码
其他回答
实际上管理插件和策略非常简单:
Goto管理控制台(localhost:15672) Goto管理选项卡 Goto Policies选项卡(在右侧) 添加政策 填充字段 虚拟主机:选择 名称:过期所有策略(稍后删除) 模式:. * 适用于:队列 定义:以值1到期(将类型从字符串更改为数字) 保存 签出队列选项卡 必须删除所有队列 不要忘记删除策略!!!!!!。
该命令删除所有队列
python rabbitmqadmin.py \
-H YOURHOST -u guest -p guest -f bash list queues | \
xargs -n1 | \
xargs -I{} \
python rabbitmqadmin.py -H YOURHOST -u guest -p guest delete queue name={}
这个脚本非常简单,因为它使用了-f bash,它以列表的形式输出队列。
然后我们使用xargs -n1将其拆分为多个变量
然后我们使用xargs -I{}来运行下面的命令,并替换命令中的{}。
下面是一种使用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)
}
下面是一个更快的版本(使用并行安装sudo apt-get install parallel),扩展了@admenva的优秀答案
parallel -j 50 rabbitmqadmin -H YOUR_HOST_OR_LOCALHOST -q delete queue name={}::: $(rabbitmqadmin -H YOUR_HOST_OR_LOCALHOST -f tsv -q list queue name)
rabbitmqadmin list queues|awk 'NR>3{print $4}'|head -n-1|xargs -I qname rabbitmqadmin delete queue name=qname