11

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

  • If application and rabbitmq runs on same machine you could get unacked with rabitmqctl command line tool with list_queues paramter. Check Matthias answer from here https://groups.google.com/forum/m/?fromgroups#!topic/rabbitmq-discuss/Q6YyFgA41JE –  Dec 05 '12 at 23:54

2 Answers2

17

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.

Mason Bryant
  • 1,372
  • 14
  • 23
  • 4
    With RabbitMQ 3.4.1, I had to leave out the `.queue` on the end of the path for this to work. – Wayne Conrad Jan 15 '15 at 17:59
  • Instead of a REST API call to this point, do we have any Java API? Because sometimes this call is getting too much time even more than a minute. That is rare but it is becoming a performance issue! – User Aug 27 '19 at 07:33
1

actual url for 3.8.9 version:

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

IlnurIbat
  • 83
  • 8