我使用spring amqp发送消息,并在ack = false的情况下使用相同的RabbitTemplate添加重发逻辑
@Bean
public RabbitTemplate customRabbitTemplate(ConnectionFactory connectionFactory) {
RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
rabbitTemplate.setMessageConverter(jackson2JsonMessageConverter());
rabbitTemplate.setMandatory(true);
rabbitTemplate.setConfirmCallback((correlationData, ack, cause) -> {
RabbitMetaMessage metaMessage = (RabbitMetaMessage) mqMsgUtil.getMetaMsg(cacheKey);
//1 receive ack
if (ack) {
// send success
mqMsgUtil.setMsgSuccess(cacheKey);
SUCESS_SEND = true;
// send failed
} else {
reSendMsg(cacheKey, metaMessage, rabbitTemplate);
}
});
public void reSendMsg(String msgId, RabbitMetaMessage rabbitMetaMessage,RabbitTemplate rabbitTemplate) {
rabbitTemplate.convertAndSend(rabbitMetaMessage)
.....
}
我第一次发送msg时可以“ 1接收确认”,但是在seSendMsg中使用RabbitTemplate再次发送msg时,我无法再次接收ack。这种情况如何?