問題描述
有沒有辦法返回未確認的消息數量?
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 隊列中未確認消息的數量的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!