python-requestsrabbitmqpika

"messages_ready" from RabbitMQ queue using Pika


I need to get the number of messages that are ready. A queue has three types of messages: 1. Total 2. Unack'd 3. Ready

Ready is the ones' that are in the queue but haven't been consumed yet.

Currently I use requests

url = "http://<RABBITHOST>:15672/api/queues/%2f/{}".format(q)
res = requests.get(url, auth=("<user>","<password>")).json()
messages_in_queue = res.get("messages_ready")

The problem here is that I have to pass in the username and password. Using Pika I believe you can get the "total" messages. Is there any way to get the other two types (unack'd and ready) using Pika?


Solution

  • No, the AMQP protocol doesn't support getting unacknowledged messages. You will still have to use the HTTP API for that. If you do a passive queue declaration, the message count returned is the number of ready messages.