Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I know that my message was sent successfully with spring amqp?

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);
like image 517
Eric Milas Avatar asked Dec 11 '11 23:12

Eric Milas


People also ask

What is AMQP spring?

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".

What is AMQP listener?

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.

How will you categorize the different message modes in AMQP?

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

How do you test RabbitMQ listener?

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.


2 Answers

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.

like image 96
Brian Kelly Avatar answered Sep 29 '22 21:09

Brian Kelly


You can use mandatory and also enable publisher returns (for undeliverable messages).

like image 36
Gary Russell Avatar answered Sep 29 '22 22:09

Gary Russell