【发布时间】:2018-02-09 08:00:14
【问题描述】:
我有一个带有 RabbitMQ 的应用程序,我使用 HTTP API (/api/queues/vhost/name) 获取 Rabbit 队列中的消息数。 但是,此信息似乎会不时刷新(默认情况下每 5 秒刷新一次)。我认为信息始终是最新的,并且在给定的时间间隔内更新的是管理页面。
有什么方法可以实时获取队列中的消息数量吗?
谢谢
【问题讨论】:
标签: rabbitmq
我有一个带有 RabbitMQ 的应用程序,我使用 HTTP API (/api/queues/vhost/name) 获取 Rabbit 队列中的消息数。 但是,此信息似乎会不时刷新(默认情况下每 5 秒刷新一次)。我认为信息始终是最新的,并且在给定的时间间隔内更新的是管理页面。
有什么方法可以实时获取队列中的消息数量吗?
谢谢
【问题讨论】:
标签: rabbitmq
管理数据库默认每 5 秒更新一次。
使用命令行rabbitmqctl list_queues 获取实时值。
尝试使用:
channel.messageCount(you_queue)
看看它是否适合你
/** * Returns the number of messages in a queue ready to be delivered * to consumers. This method assumes the queue exists. If it doesn't, * an exception will be closed with an exception. * @param queue the name of the queue * @return the number of messages in ready state * @throws IOException Problem transmitting method. */ long messageCount(String queue) throws IOException;
【讨论】: