在这篇博客的基础上了做了少许修改。具体代码如下:
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;
}
版权声明:本文为博主「佳佳」的原创文章,遵循 CC 4.0 BY-NC-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:www.liujiajia.me/2021/8/2/ho…