Using RabbitMQ is there a way to look at the queue contents without a dequeue operation?

前端 未结 3 1401
花落未央
花落未央 2020-12-13 23:49

As a way to learn RabbitMQ and python I\'m working on a project that allows me to distribute h264 encodes between a number of computers. The basics are done, I have a daemo

相关标签:
3条回答
  • 2020-12-14 00:11

    Queue browsing is not supported directly, but if you declare a queue with NO auto acknowledgements and do not ACK the messages that you receive, then you can see everything in it. After you have had a look, send a CANCEL on the channel, or disconnect and reconnect to cause all the messages to be requeued. This does increment a number in the message headers, but otherwise leaves the messages untouched.

    I built an app where message ordering was not terribly important, and I frequently scanned through the queue in this way. If I found a problem, I would dump the messages into a file, fix them and resubmit.

    If you only need to peek at a message or two once in a while you can do that with the RabbitMQ management plugin.

    In addition, if you only need a message count, you can get that every time you declare the queue, or on a basic.get command.

    0 讨论(0)
  • 2020-12-14 00:14

    @MichaelDillon based on your answer to make others life easier I am putting here a no_ack example:

    #!/usr/bin/env python
    import pika
    
    connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
    channel = connection.channel()
    
    channel.queue_declare(queue='Q.hello')
    
    
    def callback(ch, method, properties, body):
        print(" [x] Received %r" % body)
        # ch.basic_ack(delivery_tag=method.delivery_tag)
    
    channel.basic_consume(callback, queue='Q.hello')
    
    print(' [*] Waiting for messages. To exit press CTRL+C')
    channel.start_consuming()
    
    0 讨论(0)
  • 2020-12-14 00:25

    What you want to do is called browsing the queue, although I gather from this that RabbitMQ does not yet support that.

    0 讨论(0)
提交回复
热议问题