我安装了rabbitmqadmin,并且能够列出所有的交换机和队列。如何使用rabbitmqadmin或rabbitmqctl删除所有的队列。
当前回答
删除非持久队列不需要重置rabbitmq服务器。只需停止服务器并重新启动,它就会删除所有可用的非持久队列。
其他回答
下面是一种使用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)
我尝试了上面的代码段,但我没有做任何流。
Sudo rabbitmqctl list_queues | awk '{print $1}' > queues.txt;对于$(cat queue .txt)中的行;执行sudo rabbitmqctl delete_queue "$line";完成了。
我生成一个包含所有队列名称的文件,并逐行循环删除它们。对于循环,当读取…不是为了我。它总是在第一个队列名处停止。
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
如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是登录名:密码