我如何知道我的消息已使用 spring amqp 成功发送?
我正在使用 RabbitTemplate 类通过 spring amqp 写入 RabbitMQ 队列。我使用 ConvertAndSend 方法将消息发送到队列。这在正常情况下工作得很好,但如果队列不存在,它似乎会默默地失败。不会引发异常,并且不会将错误/调试消息记录到记录器中。
确保消息已送达的最佳方法是什么?
这是代码当前正在执行的操作的示例。
RabbitTemplate template = new RabbitTemplate(factory);
template.setQueue(queueName);
template.setRoutingKey(queueName);
template.convertAndSend(message);
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于 RabbitMQ 客户端将消息发送到内部没有绑定队列来接受消息的代理来说,这并不是一个错误。 RabbitMQ 会默默地丢弃它,客户端也不会知道。如果您没有对您的消息感兴趣的队列,则代理没有许多其他可用选项。
也就是说,如果消息最终会通过设置 mandatory< /a> 标志。我不知道 Spring AMQP 接口是否支持它,但它肯定可以在 RabbitMQ Java 客户端库中使用。
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).