当我使用如下代码时,发现我设置的预取值无效
@RabbitListener(queues = "test", ackMode = "MANUAL", concurrency = "3")
public void receiveMessage1(String message,
Channel channel,
@Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag
) throws IOException {
channel.basicQos(6); //这里
String res = "";
try {
Integer max = Integer.parseInt(message);
res = TestFun.test1(max);
channel.basicAck(deliveryTag, false);
} catch (Exception e) {
res = "error";
channel.basicNack(deliveryTag, false, true);
throw new RuntimeException(e);
} finally {
System.out.println("Received message: " + message);
}
}
如下图所示,明明Rabbit管理界面显示的Prefetch是6,可是未确认消息却远高于这个值
解决方法
放弃使用 channel.basicQos(6)
方法
使用SpringBoot的配置文件 application.yml
spring:
rabbitmq:
host: # RabbitMQ地址
port: # RabbitMQ端口
username: # RabbitMQ用户名
password: # RabbitMQ密码
listener:
simple:
prefetch: 6 # 在这里配置预取值
成功解决
总结
不知道这个bug是我的问题还是,SpringBoot整合RabbitMQ的问题,有大佬告知一下吗