我安装了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是登录名:密码

其他回答

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

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

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

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

这是我使用的方法。它简单、清晰、有效。 文件如下:

Vhost=the_vhost_name
User=user_name
Password=the_passworld

for i in `rabbitmqctl list_queues -p $Vhost |  awk '{ print $1 }'`
do
    echo "queu_name: $i"
    curl  -u $User:$Passworld -H "content-type:application/json"  -XDELETE http://localhost:15672/api/queues/$Vhost/$i
done