Rabbitmq+;Spring AMQP:重新发送消息但不返回ack

Rabbitmq+;Spring AMQP:重新发送消息但不返回ack,rabbitmq,amqp,spring-amqp,spring-rabbit,Rabbitmq,Amqp,Spring Amqp,Spring Rabbit,我使用springamqp发送消息,如果ack=false,则使用相同的rabbitmplate添加重发逻辑 @Bean public RabbitTemplate customRabbitTemplate(ConnectionFactory connectionFactory) { RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory); rabbitTemplate.setMessageConv

我使用springamqp发送消息,如果ack=false,则使用相同的rabbitmplate添加重发逻辑

 @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)
     .....
  }

当我第一次发送消息时,我可以“1接收ack”,但当在seSendMsg中并使用RabbitTemplate再次发送消息时,我不能再次接收ack。这是如何发生的?

不允许在ack回调上发送消息;它会导致客户端库中出现死锁。您需要在不同的线程上执行重新发送


在下一个版本(2.1)中,我们修改了代码,在不同的线程上调用回调,以避免用户代码必须这样做。请参阅及其链接。

谢谢。在其他线程上执行重新发送还有一个问题:如果重新发送成功,如何在主线程中停止重新发送?是否有进行重新发送的参考代码?