rabbitmq:消費消息時手動ack報錯(Channel shutdown: channel error; protocol method)
錯誤詳細信息:
Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=406,reply-text=PRECONDITION_FAILED - unknown delivery tag 1, class-id=60, method-id=80)
原因:采用@RabbitListener注解實現(xiàn)的消費者默認ackMode是auto,即使yml文件中配置了spring.rabbitmq.listener.simple.acknowledge-mode: manual 也不行
解決方案:
不用手動ack咆畏,直接采用默認的ack
-
設置ackMode的值為MANUAL
@RabbitListener(bindings = @QueueBinding( value = @Queue(name = "topic.dog"), exchange = @Exchange(value = "binding.dog", type = ExchangeTypes.TOPIC)), ackMode = "MANUAL" ) public void process(String msg, Channel channel, Message message) { log.info("dog-收到消息-成功:{}", msg); }