Search code examples
rabbitmqspring-rabbit

Will RabbitTemplate.convertAndSend() always throw an exception if it cannot publish?


I see that RabbitTemplate.convertAndSend() declares to throw AmqpException. Will this exception always be thrown if publishing a message will be unsuccessful or should one take extra measures, for example, using correlationConvertAndSend() along with a RabbitTemplate.ConfirmCallback.


Solution

  • Publishing to RabbitMQ is asynchronous; you will only get an exception for immediate failures (such as can't connect to the broker).

    Publisher confirms and returns are needed for guaranteed delivery.