RabbitMQ - 获取入队消息的总数 [英] RabbitMQ - Get total count of messages enqueued

查看:477
本文介绍了RabbitMQ - 获取入队消息的总数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个监控Rab​​bitMQ队列的Java客户端。我能够使用此代码获取当前队列中的消息计数

I have a Java client which monitors RabbitMQ queue. I am able to get the count of messages currently in queue with this code

@Resource
RabbitAdmin rabbitAdmin;
..........

DeclareOk declareOk = rabbitAdmin.getRabbitTemplate().execute(new ChannelCallback<DeclareOk>() {
        public DeclareOk doInRabbit(Channel channel) throws Exception {
            return channel.queueDeclarePassive("test.pending");
        }
    });
     return declareOk.getMessageCount();

我想获得更多其他细节,例如 -

I want to get some more additional details like -


  1. 当前入队项目的消息正文。

  2. 自创建队列以来队列中排队的消息总数。

有没有办法在Java客户端中检索这些数据?

Is there any way to retrieve these data in Java client?

推荐答案

使用AMQP协议(包括RabbitMQ实现),您无法获得100%保证的此类信息。

With AMQP protocol (including RabbitMQ implementation) you can't get such info with 100% guarantee.

与邮件计数最接近的数字是使用 queue.declare-ok 返回的邮件计数( AMQP.Queue.DeclareOk 在java AMQP客户端库中。)

The closest number to messages count is messages count returned with queue.declare-ok (AMQP.Queue.DeclareOk in java AMQP client library).

虽然消息计数与 queue.declare-ok 可以匹配确切的消息编号入队,你不能依赖它,因为它不计算在事务期间等待确认或发布到队列但未提交的消息然而。

Whilst messages count you receive with queue.declare-ok may match exact messages number enqueues, you can't rely on it as it doesn't count messages which waiting acknowledges or published to queue during transaction but not committed yet.

这真的取决于你需要什么样的准确性。

It really depends what kind of precission do you need.

至于排队邮件正文,你可能想手动提取队列中的所有消息,查看他们的身体并将它们放回q ueue。这是做你想做的事情的唯一方法。

As to enqueued messages body, you may want to manually extract all messages in queue, view their body and put them back to queue. This is the only way to do what you want.

你可以通过管理插件 RabbitMQ管理HTTP API rabbitmqctl util(请参阅list_queues,list_channels)。

You can get some information about messages count with Management Plugin, RabbitMQ Management HTTP API and rabbitmqctl util (see list_queues, list_channels).

自创建队列以来,您无法获得已发布的总消息数量,我认为没有人在无用时实现此类统计信息(仅供参考,消息平均每秒10k流量,几千年内甚至无法达到uint64。

You can't get total published messages count since queue was created and I think nobody implement such stats while it useless (FYI, with messages flow in average 10k per second you will not even reach uint64 in a few thousand years).

这篇关于RabbitMQ - 获取入队消息的总数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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