10
votes

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

2
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 groups.google.com/forum/m/?fromgroups#!topic/rabbitmq-discuss/…user452425

2 Answers

17
votes

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.

1
votes

actual url for 3.8.9 version:

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