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

筅森魡賤 提交于 2020-01-12 07:34:24

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/13721066/retrieving-number-of-unacknowledged-messages-in-rabbitmq-queue-from-java-spring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!