Java – how do I know my message was successfully sent using spring AMQP?

I use the rabbittemplate class to write to the rabbitmq queue using spring AMQP I use the convertandsend method to send messages to the queue This works well under normal circumstances, but if the queue does not exist, it seems to fail silently No exceptions are thrown and no error / debug messages are logged to the logger

What is the best way to ensure that mail is sent?

The following is an example of what the code is currently doing

RabbitTemplate template = new RabbitTemplate(factory);
template.setQueue(queueName);
template.setRoutingKey(queueName);
template.convertAndSend(message);

Solution

It is not an error for rabbitmq clients to send messages to agents that do not have a bound queue to accept messages Rabbitmq will silently abandon it, and the client will no longer be wise If you don't have a queue interested in your message, the broker doesn't have many other options

That is, if you set the mandatory flag, the message will be discarded silently, you can make rabbitmq complain I don't know if the spring AMQP interface supports it, but it can be used in the rabbitmq java client library

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>