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


当前回答

下面是一个更快的版本(使用并行安装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)

其他回答

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

rabbitmqadmin list queues|awk 'NR>3{print $4}'|head -n-1|xargs -I qname rabbitmqadmin delete queue name=qname

下面的命令对我有用:

sudo rabbitmqctl list_queues | awk '{print $1}' | xargs -I qn sudo rabbitmqctl delete_queue qn

另一个选项是删除与队列关联的vhost。这将删除与vhost关联的所有内容,因此请注意,但这很简单且快速。


注意:RabbitMQ团队会监控RabbitMQ用户的邮件列表,有时只在StackOverflow上回答问题。

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