Getting number of messages in a RabbitMQ queue

后端 未结 3 2086
清歌不尽
清歌不尽 2020-12-05 23:59

We\'re using amqplib to publish/consume messages. I want to be able to read the number of messages on a queue (ideally both acknowledged and unacknowledged). This will allow

3条回答
  •  旧巷少年郎
    2020-12-06 00:56

    following the answer of ChillarAnand you can get the value easily. the data is in the object.

    import pika
    
    connection = pika.BlockingConnection(pika.ConnectionParameters(
                host='localhost',
                port=5672,
                credentials=pika.credentials.PlainCredentials('guest', 'guest'),
            )
    channel = connection.channel()
    print(channel.queue_declare(queue="your_queue", durable=True,  exclusive=False,
                      auto_delete=False).method.message_count)
    

    and you will get the exact message number

提交回复
热议问题