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


当前回答

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

rabbitmqctl eval 'IfUnused = false, IfEmpty = true, MatchRegex = 
<<"^prefix-">>, [rabbit_amqqueue:delete(Q, IfUnused, IfEmpty) || Q <- 
rabbit_amqqueue:list(), re:run(element(4, element(2, Q)), MatchRegex) 
=/= nomatch ].' 

上述操作将删除所有有名称的vhosts中的所有空队列 以“前缀-”开头。 你可以编辑变量IfUnused, IfEmpty, 和MatchRegex根据您的要求。

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列表队列名称

然后从列表中,你需要逐个手动删除它们:

删除队列名

由于输出格式,您无法从列表队列中grep响应。或者,如果你只是在寻找一种方法来清除所有内容(读取:重置所有设置,将安装返回到默认状态),使用:

rabbitmqctl stop_app
rabbitmqctl reset    # Be sure you really want to do this!
rabbitmqctl start_app

要列出队列,

./rabbitmqadmin -f tsv -q list queues

要删除一个队列,

./rabbitmqadmin delete queue name=name_of_queue

有一种方法可以在不使用脚本和完全重置的情况下删除所有队列和交换机。您可以从管理界面删除并重新创建虚拟主机。这甚至适用于vhost /。

您唯一需要恢复的是新创建的vhost的权限。