开发者

Finding which task went to which queue

开发者 https://www.devze.com 2023-03-21 02:28 出处:网络
I am using RabbitMQ with Celery and I have set some custom routing settings for the task. A specific type of task goes to one queue and all the other tasks goes to another queue. Now I want to verify

I am using RabbitMQ with Celery and I have set some custom routing settings for the task. A specific type of task goes to one queue and all the other tasks goes to another queue. Now I want to verify it is working or not.

Fo开发者_StackOverflowr this, I want to inspect which tasks went to which queue. Unfortunately, I didn't find anything which could help me on this. celeryev monitor just provides information about which tasks have been received and what is their completion status. rabbitmqctl gives me information about the current running and waiting tasks only - so I cannot see to which queue did my intended task go to.

Could anyone help me with this?


You normally can't inspect messages on a queue with AMQP (not sure about Celery, though).

If you just need this as a one-off test, the simplest way would probably be to write a quick program in Python that gets all messages from the queues and prints them out.

Using py-ampqlib, this should do it:

from amqplib import client_0_8 as amqp

conn = amqp.Connection(host="localhost:5672", userid="guest", password="guest", virtual_host="/", insist=False)
chan = conn.channel()

queue_name = "the_queue"

print "Draining", queue_name

while True:
    msg = chan.basic_get(queue_name)
    if msg is None:
        break
    print msg.body

print "All done"

If you need more help, a good place to ask is the RabbitMQ Discuss mailing list. The RabbitMQ developers do their best to answer all the questions posted there, and Celery's author also reads it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号