I use spring amqp to send msg, and add the resend logic if ack=false, with the same 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)
.....
}
I can "1 receive ack" when I send msg first time, but when in seSendMsg and send msg again with RabbitTemplate, I can not receive ack again. How this happans?