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


当前回答

试试这个:

 rabbitmqadmin list queues name | awk '{print $2}' | xargs -I qn rabbitmqadmin delete queue name=qn

其他回答

下面的命令对我有用:

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

我尝试了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 /

在Rabbit 3.7.10版本中,你可以以root权限运行以下命令:

rabbitmqctl list_queues | awk '{ print $1 }' | xargs -L1 rabbitmqctl delete_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)
 }

要列出队列,

./rabbitmqadmin -f tsv -q list queues

要删除一个队列,

./rabbitmqadmin delete queue name=name_of_queue