问题
-
Queued messages : 统计消息的条数一直为 0
-
Message rates:统计消费的速率一直有数据
-
数据库数据已经入库,表示消息确实被消费了。
总体
明细
通过手动的方式发送消息,也不能统计到。
但是关闭消费者程序之后,手动发送消息就可以统计到了
继续排查
那么手动加一个队列 test.queue
手动发一条消息,发现正常显示
继续测试
将生产者修改为 每100毫秒发送100条消息,发送5次
@RequestMapping("/test")
@ResponseBody
public Integer test(Integer id) throws InterruptedException {
int count = 0;
for (; ; ) {
if (count == 5) break;
for (int i = 0; i < 100; i++) {
gupaoTemplate.convertAndSend("GP_DIRECT_EXCHANGE", "test", "消息" + i);
System.out.println("消息" + i);
}
Thread.sleep(100);
count++;
}
return 1;
}
将消费者修改为 每消费一条睡眠100毫秒,设置了手动签收,消费完最后签收。
@Service
public class TestConsumer {
@RabbitListener(queues = "test.queue")
public void saveQuotaComment(Message message, Channel channel) throws InterruptedException, IOException {
Thread.sleep(100);
System.out.println(">>>>>>>>>>>>>>>>>>>"+new String(message.getBody()));
channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
}
}
这样保证消费者的消费速度跟不上消息的生产速度。
Queued messages 终于有数据。
总结
Queued messages 显示的是消息堆积之后的监控数据,并非所有的消息都会记录在里面,如果消息消费的过快,不会有数据显示。
感谢咕泡学院-青山老师的帮助,贴上青山老师的回答。