报错内容:

java.lang.IllegalStateException: Channel closed; cannot ack/nack

可能1,rabbitmq的配置文件需要设置

spring:
rabbitmq:
listener:
direct:
#手动确认
acknowledge-mode: manual
simple:
#手动确认
acknowledge-mode: manual

可能2,可能我们在工厂里设置了自己的json解析器,需要在工厂类里再次重新设置一下手动ack

@Bean
public RabbitListenerContainerFactory<?> rabbitListenerContainerFactory(ConnectionFactory connectionFactory){
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
factory.setMessageConverter(new Jackson2JsonMessageConverter());
factory.setAcknowledgeMode(AcknowledgeMode.MANUAL); //开启手动 ack
return factory;
}