Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving number of unacknowledged messages in RabbitMQ queue from Java/ Spring

is there any way to return the number of messages that are unacknowledged?

I am using this code to get the number of messages in the queue:

DeclareOk declareOk = amqpAdmin.getRabbitTemplate().execute(
        new ChannelCallback<DeclareOk>() {
            public DeclareOk doInRabbit(Channel channel)
                throws Exception {
                return channel.queueDeclarePassive(name);
            }
        });
return declareOk.getMessageCount();

but I would like to know as well the number of unacknowledged messages.

I have seen that the RabbitMQ Admin tool includes that information (for each queue it gives out the number of Ready/ Unacked and Total messages) and I guess there must be a way to retrieve that from Java/ Spring.

Thanks

UPDATE

Oks, it seems there is no way to accomplish that programmatically since listing of configuration/ queues is not part of AMPQ.

There is the possibility to enable the management plugin and query the REST web services about the queues (among other things). More info here:

http://www.rabbitmq.com/management.html

like image 552
Javier Moreno Garcia Avatar asked Dec 05 '12 10:12

Javier Moreno Garcia


People also ask

How do I find my RabbitMQ queue size?

The passive argument to queue_declare allows you to check whether a queue exists without modifying the server state, so you can use queue_declare with the passive option to check the queue length. This should be the accepted answer, even if he did miss Basic. Get as the 2nd source of this info.

What happens to unacknowledged messages in RabbitMQ?

RabbitMQ Unacked Messages are the messages that are not Acknowledged. If a consumer fails to acknowledge messages, the RabbitMQ will keep sending new messages until the prefetch value set for the associated channel is equal to the number of RabbitMQ Unacked Messages count.

How do I get all messages from RabbitMQ?

exports = (connection, queue) => { init(connection, queue); return { getMessages: (queueName, cleanQueue) => new Promise((resolve) => { let messages = []; let i = 1; getChannel(). then((ch) => { ch. consume(queueName, (msg) => { messages. push(msg); console.

How many messages can a RabbitMQ queue hold?

Queues are single-threaded in RabbitMQ, and one queue can handle up to about 50 thousand messages. You will achieve better throughput on a multi-core system if you have multiple queues and consumers and if you have as many queues as cores on the underlying node(s).


2 Answers

As you say in your update, if you enable the management plugin, you can query the rest api:

Eg:

`http://username:password@queue-server:15672/api/queues/%2f/queue_name.queue`

This returns json with (among other things)

  • messages_unacknowledged
  • messages_ready

It's good stuff if you have a safe route to the server.

like image 136
Mason Bryant Avatar answered Oct 18 '22 16:10

Mason Bryant


actual url for 3.8.9 version:

http://username:password@queue-server:15672/api/queues/%2F/queue-name

like image 44
IlnurIbat Avatar answered Oct 18 '22 18:10

IlnurIbat