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


当前回答

试试这个:

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

其他回答

下面是一种使用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)
 }

该命令删除所有队列

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{}来运行下面的命令,并替换命令中的{}。

我尝试了上面的代码段,但我没有做任何流。

Sudo rabbitmqctl list_queues | awk '{print $1}' > queues.txt;对于$(cat queue .txt)中的行;执行sudo rabbitmqctl delete_queue "$line";完成了。

我生成一个包含所有队列名称的文件,并逐行循环删除它们。对于循环,当读取…不是为了我。它总是在第一个队列名处停止。

在Rabbit 3.7.10版本中,你可以以root权限运行以下命令:

rabbitmqctl list_queues | awk '{ print $1 }' | xargs -L1 rabbitmqctl delete_queue

如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是登录名:密码