<!-- # 获取 RabbitMQ 的消息数量 --> <!-- how-to-get-message-count-of-rabbit-mq --> 在[这篇博客][1]的基础上了做了少许修改。具体代码如下: ```java private final RabbitTemplate rabbitTemplate; try (Connection connection = rabbitTemplate.getConnectionFactory().createConnection(); Channel channel = connection.createChannel(false);) { // 设置消息交换机 channel.exchangeDeclare("amp.topic", "topic", true, false, null); AMQP.Queue.DeclareOk declareOk = channel.queueDeclarePassive(QUEUE_NAME); //获取队列中的消息个数 int queueCount = declareOk.getMessageCount(); return queueCount; } ``` [1]:https://www.cnblogs.com/commissar-Xia/p/11363435.html (RabbitMQ获取队列的消息数目) Loading... 版权声明:本文为博主「佳佳」的原创文章,遵循 CC 4.0 BY-NC-SA 版权协议,转载请附上原文出处链接及本声明。 原文链接:https://www.liujiajia.me/2021/8/2/how-to-get-message-count-of-rabbit-mq ← 上一篇 下一篇 → 提交