Search code examples
rabbitmqerlangelixiramqp

Can I see the count of unacked messages in RabbitMQ via an AMQP client?


In the RabbitMQ web UI, I can see, for each queue, the number of messages that are ready to be consumed and the number that are being processed but have not yet been acked.

Screenshot from UI with the "Messages" section for a specific queue showing columns "Ready", "Unacked", and "Total", each with a number

However, I don't see how to get the number of unacked messages via an AMQP client.

For instance, the AMQP.Queue.message_count/2 function in the Elixir client uses the underlying Erlang library to re-declare the queue with passive: true and gets back message_count and consumer_count fields, but the message_count includes only messages that are "ready for delivery (e.g. not pending acknowledgements)".

My goal is to see how big a backlog of messages I currently have. For my purposes, those that are currently being processed are just as much a part of that as those that are ready for processing.

How can I get a count of unacked messages for a given RabbitMQ queue using an AMQP client?


Solution

  • AMQP 0.9-1 does not have that information in the Declare-OK message, nor do I see that in RabbitMQ's AMQP extensions.

    If your consumers are similar, you could get use the approximation Total = Ready + ConsumerCount * QoS (QoS being the prefetch count for each consumer), taking into account that if Ready == 0, the approximation is an upper limit (because it's possible for the broker to not have enough messages to satisfy all the consumers).

    You have another option, which is using the stats provided by the management plugin through the REST API