Search code examples
springrabbitmqamqpspring-amqpspring-rabbit

Validate exchange, routing key when publishing message using Spring RabbitMessagingTemplate


Is there a way to validate that the exchange and routing key/queue when sending message using RabbitMessagingTemplate? Currently, there is a default exchange and routing key which blank string and there's no error being thrown.

messagingTemplate.convertAndSend(message.getExchange(), message.getRoutingKey(), message.getPayload());

Solution

  • Please, see Returns and Confirms callback: https://docs.spring.io/spring-amqp/docs/2.1.2.RELEASE/reference/html/_reference.html#template-confirms. So, if there is anything wrong with exchange or queue on the routing key, you’re going to have message returned with an error