解决rabbitmq ConfirmCallback不回调的问题
问题描述
- 实现了RabbitTemplate.ConfirmCallback接口,并重写了confirm方法
- 配置了publisher-confirms: true
- 发送消息到RabbitMq,已经发送成功,也已经到队列中了,且状态为ready,但是并没有回调方法
解决办法
- 添加属性publisher-confirm-type: correlated
spring.rabbitmq.publisher-confirm-type=correlated
问题原因
新版本publisher-confirms已经修改为publisher-confirm-type,默认为NONE,即不进行确认
/**
* The type of publisher confirms to use.
*/
public enum ConfirmType {
/**
* Use {@code RabbitTemplate#waitForConfirms()} (or {@code waitForConfirmsOrDie()}
* within scoped operations.
*/
SIMPLE,
/**
* Use with {@code CorrelationData} to correlate confirmations with sent
* messsages.
*/
CORRELATED,
/**
* Publisher confirms are disabled (default).
*/
NONE
}
- 确认回调正常