我如何知道我的消息已使用 spring amqp 成功发送?

发布于 2024-12-20 20:06:49 字数 379 浏览 4 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雨落星ぅ辰 2024-12-27 20:06:49

对于 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.

故事与诗 2024-12-27 20:06:49

您可以使用强制,还可以启用发布者退货(针对无法送达的邮件)。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文