从 Java/Spring 中检索 RabbitMQ 队列中未确认消息的数量 [英] Retrieving number of unacknowledged messages in RabbitMQ queue from Java/ Spring

查看:47
本文介绍了从 Java/Spring 中检索 RabbitMQ 队列中未确认消息的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法返回未确认的消息数量?

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.

我已经看到 RabbitMQ 管理工具包含该信息(对于每个队列,它给出了 Ready/Unacked 和 Total 消息的数量),我想一定有一种方法可以从 Java/Spring 中检索这些信息.

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.

谢谢

更新

好吧,似乎没有办法以编程方式完成,因为配置/队列列表不是 AMPQ 的一部分.

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

可以启用管理插件并查询有关队列的 REST Web 服务(除其他外).更多信息在这里:

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

推荐答案

如你更新中所说,如果开启管理插件,可以查询其余api:

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

例如:

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

这会返回带有(除其他外)的 json

This returns json with (among other things)

  • messages_unacknowledged
  • messages_ready

如果您有一条通往服务器的安全路线,那就太好了.

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

这篇关于从 Java/Spring 中检索 RabbitMQ 队列中未确认消息的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆