Has anybody used Elixir to check the length of a RabbitMQ queue? It can be done with
declare_queue, but it’s ugly - you have to pass the exact option you originally declared the queue with, plus
The use case is to detect when the system is backing up and respond accordingly.
If you can use
GenRmq then it has message count, message_count functions.
For anyone who stumbles on this later: AMQP only supports getting the number of messages that are “Ready”, not those that are “unacked”. For the latter, you might have to use RabbitMQ’s REST API. See https://stackoverflow.com/questions/63018151/can-i-see-the-count-of-unacked-messages-in-rabbitmq-via-an-amqp-client
My system that consumes from the queue is using Broadway. In normal load, I basically never see any messages as “ready” because they’re quickly grabbed up by my Broadway pipeline. By queueing a lot of messages and putting a
Process.sleep(:infinity) in my
handle_message, I can see that my system will have at most N unacked messages at a time. So if I see any messages in the “ready” count, I can basically assume that there are N more being handled at the moment, which is a good enough indicator to decide whether the system is getting overloaded.