繁体   English   中英

如何获取Spring-AMQP中已经声明的队列的使用者计数?

[英]How to get the consumer count of an already declared queue in Spring-AMQP?

有没有办法找出Spring AMQP中已经声明的队列的订户计数? 我找到了一个com.rabbitmq.client.Channel类,可以使用它来执行以下操作:

int consumerCount = channel.queueDeclare().getConsumerCount();

但是,这将声明一个具有随机名称的新队列,并且由于它没有使用者,因此它将返回0

有什么办法可以对已经声明的队列进行处理吗?

您可以使用被动声明

被动声明仅检查具有提供名称的实体是否存在。 如果是这样,则该操作为无操作。 对于成功的队列,被动声明将返回与非被动声明相同的信息,即队列中处于就绪状态的使用者和消息的数量。

Queue.DeclareOk response = channel.queueDeclarePassive("queue-name");
// returns the number of messages in Ready state in the queue
response.getMessageCount();
// returns the number of consumers the queue has
response.getConsumerCount();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM