Check RabbitMQ queue size from client

后端 未结 9 1109
终归单人心
终归单人心 2021-01-30 20:12

Does anyone know if there\'s a way to check the number of messages in a RabbitMQ queue from a client application?

I\'m using the .NET client library.

9条回答
  •  粉色の甜心
    2021-01-30 20:48

    Update: it appears that the pika implementation of queue_declare(..) has changed since mmalone's very helpful post.

    In python/pika (v0.9.5) it's still possible to check the queue depth via pika, but it requires a slightly more indirect approach.

    queue_declare(...) passes a method object into its callback function, which you can then inspect. For example, to check the number of messages and consumers in the queue named 'myQueue':

    def cbInspect(qb):
        messagesInQueue = qb.method.message_count
        print "There are %d messages in myQueue" % messagesInQueue
    
        consumersInQueue = qb.method.consumer_count
        print "There are %d consumers in myQueue" % consumersInQueue
    
        return
    
    myChannel = channel.queue_declare(callback=cbInspect, queue='myQueue', passive=True)
    

    Hope this helps, and please go easy on me, I'm new around here :-)

提交回复
热议问题