我安装了rabbitmqadmin,并且能够列出所有的交换机和队列。如何使用rabbitmqadmin或rabbitmqctl删除所有的队列。
当前回答
删除非持久队列不需要重置rabbitmq服务器。只需停止服务器并重新启动,它就会删除所有可用的非持久队列。
其他回答
如果你没有安装rabbitmqadmin,尝试使用rabbitmqctl清除队列:
rabbitmqctl list_queues | awk '{print $1}' | xargs -L1 rabbitmqctl purge_queue . txt
要列出队列,
./rabbitmqadmin -f tsv -q list queues
要删除一个队列,
./rabbitmqadmin delete queue name=name_of_queue
下面是一种使用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)
}
我尝试了rabbitmqctl和reset命令,但它们非常慢。
这是我找到的最快的方法(替换用户名和密码):
#!/bin/bash
# Stop on error
set -eo pipefail
USER='guest'
PASSWORD='guest'
curl -sSL -u $USER:$PASSWORD http://localhost:15672/api/queues/%2f/ | jq '.[].name' | sed 's/"//g' | xargs -L 1 -I@ curl -XDELETE -sSL -u $USER:$PASSWORD http://localhost:15672/api/queues/%2f/@
# To also delete exchanges uncomment next line
# curl -sSL -u $USER:$PASSWORD http://localhost:15672/api/exchanges/%2f/ | jq '.[].name' | sed 's/"//g' | xargs -L 1 -I@ curl -XDELETE -sSL -u $USER:$PASSWORD http://localhost:15672/api/exchanges/%2f/@
注意:这只适用于默认vhost /
使用rabbitmqctl一行删除所有队列
rabbitmqctl list_queues | awk '{ print $1 }' | sed 's/Listing//' | xargs -L1 rabbitmqctl purge_queue