nathanl
Monitor RabbitMQ queue length from Elixir?
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 :passive.
The use case is to detect when the system is backing up and respond accordingly.
Most Liked
collegeimprovements
If you can use GenRmq then it has message count, message_count functions.
nathanl
@collegeimprovements Oh thanks - that led me to the underlying function: AMQP.Queue — amqp v1.4.2 . Works great!
nathanl
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.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #javascript
- #code-sync
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








