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

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.


您可以使用mandatory并且还可以启用发布商退货(对于无法投递的消息)。

链接地址: http://www.djcxy.com/p/10234.html

上一篇: 如何使用Delphi从命令行编译Win32程序

下一篇: 我如何知道我的消息是使用spring amqp成功发送的?