IT

RabbitMQ에서 모든 대기열을 삭제 하시겠습니까?

lottoking 2020. 5. 21. 08:32
반응형

RabbitMQ에서 모든 대기열을 삭제 하시겠습니까?


rabbitmqadmin모든 교환 및 대기열을 설치 하고 나열 할 수있었습니다. 모든 대기열을 사용 rabbitmqadmin하거나 rabbitmqctl삭제하려면 어떻게해야합니까 ?


먼저 대기열을 나열하십시오.

rabbitmqadmin list queues name

그런 다음 목록에서 하나씩 수동으로 삭제해야합니다.

rabbitmqadmin delete queue name='queuename'

출력 형식으로 인해에서 응답을 grep 할 수 없습니다 list queues. 또는 모든 것을 지우는 방법을 찾고 있다면 (읽기 : 모든 설정 재설정 , 설치를 기본 상태로 되돌리기) 다음을 사용하십시오.

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

으로 rabbitmqadmin당신이 한 줄에 제거 할 수 있습니다 :

rabbitmqadmin -f tsv -q list queues name | while read queue; do rabbitmqadmin -q delete queue name=${queue}; done

관리 플러그인 및 정책으로 실제로 매우 쉽습니다.

  • Goto 관리 콘솔 (localhost : 15672)

  • 고토 관리자

  • Goto Policies ( 고토 정책) 탭 (오른쪽)

  • 정책 추가

  • 필드 채우기

    • 가상 호스트 : 선택
    • 이름 : 모든 정책 만료 (나중에 삭제)
    • 패턴 : . *
    • 적용 : 대기열
    • 정의 : 1로 만료 (유형을 문자열에서 숫자로 변경)
  • 저장

  • 결제 대기열 탭을 다시
  • 모든 대기열을 삭제해야합니다
  • 그리고 정책 제거를 잊지 마세요 !!!!!! .

이 시도:

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

rabbitmqadmin이 설치되어 있지 않은 경우 rabbitmqctl로 대기열을 제거하십시오.

rabbitmqctl list_queues | awk '{ print $1 }' | xargs -L1 rabbitmqctl purge_queue


deleteRabbitMqQs.sh를 작성했습니다.이 인수는 인수 목록을 검색하여 대기열 목록을 검색하고 원하는 패턴과 일치하는 대기열 만 선택합니다. 인수를 제공하지 않으면 모두 삭제됩니다! 삭제하려고하는 대기열의 목록을 보여 주므로 파괴적인 작업을하기 전에 종료 할 수 있습니다.

for word in "$@"
do
        args=true
        newQueues=$(rabbitmqctl list_queues name | grep "$word")
        queues="$queues
$newQueues"
done
if [ $# -eq 0 ]; then
        queues=$(rabbitmqctl list_queues name | grep -v "\.\.\.")
fi

queues=$(echo "$queues" | sed '/^[[:space:]]*$/d')

if [ "x$queues" == "x" ]; then
        echo "No queues to delete, giving up."
        exit 0
fi

read -p "Deleting the following queues:
${queues}
[CTRL+C quit | ENTER proceed]
"

while read -r line; do
        rabbitmqadmin delete queue name="$line"
done <<< "$queues"

전달한 인수에 대해 다른 일치를 원하면 4 행에서 grep을 변경할 수 있습니다. 모든 큐를 삭제할 때 연속 된 공백이 3 개인 큐는 삭제되지 않습니다. 왜냐하면 다른 언어로 출력을 출력하는 rabbitmqctl을 가진 사람들보다 드문 경우 일 것입니다.

즐겨!


If you're trying to delete queues because they're unused and you don't want to reset, one option is to set the queue TTL very low via a policy, wait for the queues to be auto-deleted once the TTL is passed and then remove the policy (https://www.rabbitmq.com/ttl.html).

rabbitmqctl.bat set_policy delq ".*" '{"expires": 1}' --apply-to queues

To remove the policy

rabbitmqctl clear_policy delq

Note that this only works for unused queues

Original info here: http://rabbitmq.1065348.n5.nabble.com/Deleting-all-queues-in-rabbitmq-td30933.html


Here is a way to do it with PowerShell. the URL may need to be updated

$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)
 }

You can use rabbitmqctl eval as below:

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 ].' 

The above will delete all empty queues in all vhosts that have a name beginning with "prefix-". You can edit the variables IfUnused, IfEmpty, and MatchRegex as per your requirement.


Removing all queues using rabbitmqctl one liner

rabbitmqctl list_queues | awk '{ print $1 }' | sed 's/Listing//' | xargs -L1 rabbitmqctl purge_queue

In Rabbit version 3.7.10 you can run below command with root permission:

rabbitmqctl list_queues | awk '{ print $1 }' | xargs -L1 rabbitmqctl delete_queue

In case you only want to purge the queues which are not empty (a lot faster):

rabbitmqctl list_queues | awk '$2!=0 { print $1 }' | sed 's/Listing//' | xargs -L1 rabbitmqctl purge_queue

For me, it takes 2-3 seconds to purge a queue (both empty and non-empty ones), so iterating through 50 queues is such a pain while I just need to purge 10 of them (40/50 are empty).


I tried rabbitmqctl and reset commands but they are very slow.

This is the fastest way I found (replace your username and password):

#!/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/@

Note: This only works with the default vhost /


To list queues,

./rabbitmqadmin -f tsv -q list queues

To delete a queue,

./rabbitmqadmin delete queue name=name_of_queue

Here is a faster version (using parallel install sudo apt-get install parallel) expanding on the excellent answer by @admenva

parallel -j 50 rabbitmqadmin -H YOUR_HOST_OR_LOCALHOST -q delete queue name={} ::: $(rabbitmqadmin -H YOUR_HOST_OR_LOCALHOST -f tsv -q list queues name)


This commands deletes all your queues

python rabbitmqadmin.py \
  -H YOURHOST -u guest -p guest -f bash list queues | \
xargs -n1 | \
xargs -I{} \
  python rabbitmqadmin.py -H YOURHOST -u guest -p guest delete queue name={}

This script is super simple because it uses -f bash, which outputs the queues as a list.

Then we use xargs -n1 to split that up into multiple variables

Then we use xargs -I{} that will run the command following, and replace {} in the command.


You need not reset rabbitmq server to delete non-durable queues. Simply stop the server and start again and it will remove all the non-durable queues available.


There's a way to remove all queues and exchanges without scripts and full reset. You can just delete and re-create a virtual host from admin interface. This will work even for vhost /.

The only thing you'll need to restore is permissions for the newly created vhost.


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


Another option is to delete the vhost associated with the queues. This will delete everything associated with the vhost, so be warned, but it is easy and fast.


NOTE: the RabbitMQ team monitors the rabbitmq-users mailing list and only sometimes answers questions on StackOverflow.


I tried the above pieces of code but I did not do any streaming.

sudo rabbitmqctl list_queues | awk '{print $1}' > queues.txt; for line in $(cat queues.txt); do sudo rabbitmqctl delete_queue "$line"; done.

I generate a file that contains all the queue names and loops through it line by line to the delete them. For the loops, while read ... did not do it for me. It was always stopping at the first queue name.


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

참고URL : https://stackoverflow.com/questions/11459676/delete-all-the-queues-from-rabbitmq

반응형