How do I know if my message was sent successfully using spring amqp?

I am writing to the RabbitMQ queue using spring amqp using the RabbitTemplate class. I use the convertAndSend method to send messages to the queue. This works well in normal situations, but does not seem to work if the queue does not exist. No exception is thrown and no error / debugging message is logged.

What is the best way to verify that a message has been delivered?

Here is an example of what the code is currently doing.

RabbitTemplate template = new RabbitTemplate(factory); template.setQueue(queueName); template.setRoutingKey(queueName); template.convertAndSend(message); 
+6
source share
2 answers

It is not a mistake for the RabbitMQ client to send a message to a broker who has no restrictions associated with it in order to receive the message. RabbitMQ will quietly drop it, and the client will not become wiser. If you do not have queues interested in your messages, the broker has no other options available to him.

However, you can make RabbitMQ complain if the message ends silently by setting the flag to mandatory . I don't know if its Spring AMQP interfaces support it, but it is certainly available in the RabbitMQ Java client library.

+2
source

You can use mandatory , as well as allow the publisher to return (for undeliverable messages).

+1
source

Source: https://habr.com/ru/post/903560/


All Articles