获取 RabbitMQ 的消息数量
🏷️ RabbitMQ
在这篇博客的基础上了做了少许修改。具体代码如下:
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
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11