Retrieving number of unacknowledged messages in RabbitMQ queue from Java/ Spring(从 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 队列中未确认消息的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从 Java/Spring 中检索 RabbitMQ 队列中未确认消息的数


基础教程推荐
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01