I am writing to a RabbitMQ queue with spring amqp using the RabbitTemplate class. I use the convertAndSend method to send messages to the queue. This works well under normal situations, but it seems to fail silently if the queue doesn't exist. No exception is thrown and no error/debug message is logged to the logger.
What is the best way for me to make sure the message was delivered?
Here is an example of what the code is doing currently.
RabbitTemplate template = new RabbitTemplate(factory);
template.setQueue(queueName);
template.setRoutingKey(queueName);
template.convertAndSend(message);
The Spring AMQP project applies core Spring concepts to the development of AMQP-based messaging solutions. It provides a "template" as a high-level abstraction for sending and receiving messages. It also provides support for Message-driven POJOs with a "listener container".
AMQP stands for Advances Messaging Queing Protocol. The AMQP listener can be used to read from an AMQP destination. This destination can be a queue or topic in an AMQP environment. The connection factory determines which AMQP environment will be used.
AMQP allows for various guaranteed messaging modes specifying a message be sent: At-most-once(sent one time with the possibility of being missed). At-least-once (guaranteeing delivery with the possibility of duplicated messages). Exactly-once (guaranteeing a one-time only delivery).
In order to test that our Listener is capable of consuming the messages, first we must send a test message. . . . @Autowired private lateinit var rabbitTemplate: RabbitTemplate @Autowired private lateinit var rabbitAdmin: RabbitAdmin @Before fun setUp() { rabbitAdmin.
It's not an error for a RabbitMQ client to send a message to a broker which has no queues bound within it to accept the message. RabbitMQ will silently drop it and the client will be none the wiser. If you've no queues interested in your messages, the broker has not got many other options available to it.
That said, you can make RabbitMQ complain if the message will end up silently dropped by setting the mandatory flag. I don't know if the Spring AMQP interfaces support it, but it's certainly available in the RabbitMQ Java client library.
You can use mandatory
and also enable publisher returns (for undeliverable messages).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With