RabbitMQ에서 대기열 삭제
RabbitMQ로 실행되는 몇 개의 대기열이 있습니다. 그중 일부는 현재 사용되지 않습니다. 어떻게 삭제할 수 있습니까? 불행히도 나는 auto_delete
옵션을 설정하지 않았습니다 .
지금 설정하면 삭제 되나요?
지금 해당 대기열을 삭제하는 방법이 있습니까?
다른 대기열에 관심이 없다면 다음 명령을 순서대로 실행하여 명령 줄을 통해 모든 대기열을 제거 할 수 있습니다.
경고 : 이렇게하면 토끼 서버에서 구성한 모든 사용자 와 가상 호스트 도 삭제 됩니다 .
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl start_app
rabbitmq 문서에는 다음 reset
명령이 나와 있습니다.
속한 클러스터에서 노드를 제거하고 구성된 사용자 및 가상 호스트와 같은 관리 데이터베이스에서 모든 데이터를 제거하며 모든 지속성 메시지를 삭제합니다.
따라서 사용에주의하십시오.
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters(
'localhost'))
channel = connection.channel()
channel.queue_delete(queue='queue-name')
connection.close()
다음과 같이 pika 패키지를 설치하십시오.
$ sudo pip install pika==0.9.8
설치는 pip 및 git-core 패키지에 따라 다르며 먼저 설치해야 할 수도 있습니다.
Ubuntu에서 :
$ sudo apt-get install python-pip git-core
데비안 :
$ sudo apt-get install python-setuptools git-core
$ sudo easy_install pip
Windows : easy_install을 설치하려면 setuptools 용 MS Windows Installer를 실행하십시오.
> easy_install pip
> pip install pika==0.9.8
RabbitMQ 버전> 3.0에서 rabbitmq_management 플러그인이 활성화 된 경우 HTTP API를 사용할 수도 있습니다. content-type을 'application / json'으로 설정하고 가상 호스트 및 대기열 이름을 제공하십시오.
IE 가상 호스트 'test'및 큐 이름 'testqueue'와 함께 curl 사용 :
$ curl -i -u guest:guest -H "content-type:application/json" -XDELETE http://localhost:15672/api/queues/test/testqueue
HTTP/1.1 204 No Content
Server: MochiWeb/1.1 WebMachine/1.9.0 (someone had painted it blue)
Date: Tue, 16 Apr 2013 10:37:48 GMT
Content-Type: application/json
Content-Length: 0
콘솔에서 작업하기에 좋은 rabbitmqadmin 이 있습니다 .
Rabbit이 설치된 서버에 ssh / 로그인하면 다음에서 다운로드 할 수 있습니다.
http://{server}:15672/cli/rabbitmqadmin
/ usr / local / bin / rabbitmqadmin에 저장합니다.
그런 다음 실행할 수 있습니다
rabbitmqadmin -u {user} -p {password} -V {vhost} delete queue name={name}
일반적으로 sudo가 필요합니다.
If you want to avoid typing your user name and password, you can use config
rabbitmqadmin -c /var/lib/rabbitmq/.rabbitmqadmin.conf -V {vhost} delete queue name={name}
All that under assumption that you have file ** /var/lib/rabbitmq/.rabbitmqadmin.conf** and have bare minumum
hostname = localhost
port = 15672
username = {user}
password = {password}
EDIT: As of comment from @user299709, it might be helpful to point out that user must be tagged as 'administrator' in rabbit. (https://www.rabbitmq.com/management.html)
You assert that a queue exists (and create it if it does not) by using queue.declare. If you originally set auto-delete to false, calling queue.declare again with autodelete true will result in a soft error and the broker will close the channel.
You need to use queue.delete now in order to delete it.
See the API documentation for details:
If you use another client, you'll need to find the equivalent method. Since it's part of the protocol, it should be there, and it's probably part of Channel or the equivalent.
You might also want to have a look at the rest of the documentation, in particular the Geting Started section which covers a lot of common use cases.
Finally, if you have a question and can't find the answer elsewhere, you should try posting on the RabbitMQ Discuss mailing list. The developers do their best to answer all questions asked there.
A short summary for quick queue deletion with all default values from the host that is running RMQ server:
curl -O http://localhost:15672/cli/rabbitmqadmin
chmod u+x rabbitmqadmin
./rabbitmqadmin delete queue name=myQueueName
To delete all queues matching a pattern in a given vhost (e.g. containing 'amq.gen' in the root vhost):
rabbitmqctl -p / list_queues | grep 'amq.gen' | cut -f1 -d$'\t' | xargs -I % ./rabbitmqadmin -V / delete queue name=%
Another option would be to enable the management_plugin and connect to it over a browser. You can see all queues and information about them. It is possible and simple to delete queues from this interface.
I've generalized Piotr Stapp's JavaScript/jQuery method a bit further, encapsulating it into a function and generalizing it a bit.
This function uses the RabbitMQ HTTP API to query available queues in a given vhost
, and then delete them based on an optional queuePrefix
:
function deleteQueues(vhost, queuePrefix) {
if (vhost === '/') vhost = '%2F'; // html encode forward slashes
$.ajax({
url: '/api/queues/'+vhost,
success: function(result) {
$.each(result, function(i, queue) {
if (queuePrefix && !queue.name.startsWith(queuePrefix)) return true;
$.ajax({
url: '/api/queues/'+vhost+'/'+queue.name,
type: 'DELETE',
success: function(result) { console.log('deleted '+ queue.name)}
});
});
}
});
};
Once you paste this function in your browser's JavaScript console while on your RabbitMQ management page, you can use it like this:
Delete all queues in '/' vhost
deleteQueues('/');
Delete all queues in '/' vhost beginning with 'test'
deleteQueues('/', 'test');
Delete all queues in 'dev' vhost beginning with 'foo'
deleteQueues('dev', 'foo');
Please use this at your own risk!
The management plugin (web interface) gives you a link to a python script. You can use it to delete queues. I used this pattern to remove a lot of queues:
python tmp/rabbitmqadmin --vhost=... --username=... --password=... list queues > tmp/q
vi tmp/q # remove all queues which you want to keep
cut -d' ' -f4 tmp/q| while read q;
do python tmp/rabbitmqadmin --vhost=... --username=... --password=... delete queue name=$q;
done
I use this alias in .profile
:
alias qclean="rabbitmqctl list_queues | python ~/bin/qclean.py"
where qclean.py
has the following code:
import sys
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
queues = sys.stdin.readlines()[1:-1]
for x in queues:
q = x.split()[0]
print 'Deleting %s...' %(q)
channel.queue_delete(queue=q)
connection.close()
Essentially, this is an iterative version of code of Shweta B. Patil.
With the rabbitmq_management plugin installed you can run this to delete all the unwanted queues:
rabbitmqctl list_queues -p vhost_name |\
grep -v "fast\|medium\|slow" |\
tr "[:blank:]" " " |\
cut -d " " -f 1 |\
xargs -I {} curl -i -u guest:guest -H "content-type:application/json" -XDELETE http://localhost:15672/api/queues/<vhost_name>/{}
Let's break the command down:
rabbitmqctl list_queues -p vhost_name
will list all the queues and how many task they have currently.
grep -v "fast\|medium\|slow"
will filter the queues you don't want to delete, let's say we want to delete every queue without the words fast, medium or slow.
tr "[:blank:]" " "
will normalize the delimiter on rabbitmqctl between the name of the queue and the amount of tasks there are
cut -d " " -f 1
will split each line by the whitespace and pick the 1st column (the queue name)
xargs -I {} curl -i -u guest:guest -H "content-type:application/json" -XDELETE http://localhost:15672/api/queues/<vhost>/{}
will pick up the queue name and will set it into where we set the {}
character deleting all queues not filtered in the process.
Be sure the user been used has administrator permissions.
install
$ sudo rabbitmq-plugins enable rabbitmq_management
and go to http://localhost:15672/#/queues if you are using localhost. the default password will be username: guest
, password: guest
and go to queues tab and delete the queue.
I did it different way, because I only had access to management webpage. I created simple "snippet" which delete queues in Javascript. Here it is:
function zeroPad(num, places) {
var zero = places - num.toString().length + 1;
return Array(+(zero > 0 && zero)).join("0") + num;
}
var queuePrefix = "PREFIX"
for(var i=0; i<255; i++){
var queueid = zeroPad(i, 4);
$.ajax({url: '/api/queues/vhost/'+queuePrefix+queueid, type: 'DELETE', success: function(result) {console.log('deleted '+queuePrefix+queueid)}});
}
All my queues was in format: PREFIX_0001 to PREFIX_0XXX
Hopefully it might help someone.
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.
Also, if you want to delete a single queue, the above solutions will help(python, Java ...) and also do sudo rabbitmqctl delete_queue queue_name
. I am using rabbitmqctl
instead of rabbitmqadmin
.
참고URL : https://stackoverflow.com/questions/6742938/deleting-queues-in-rabbitmq
'development' 카테고리의 다른 글
PHP 시스템의 로컬 IP를 얻는 방법 (0) | 2020.09.17 |
---|---|
파이썬에서 "역전 된"목록을 만드는 가장 좋은 방법은 무엇입니까? (0) | 2020.09.17 |
orderby 필터가 문자열 배열에서 작동하도록 만드는 방법은 무엇입니까? (0) | 2020.09.17 |
동일한 임의의 numpy 배열을 일관되게 생성 (0) | 2020.09.17 |
구성표에 대한 파일 시스템 없음 : 파일 (0) | 2020.09.17 |