我可以在 AMQP 中多次使用相同的关联 ID 吗?

发布于 2024-10-31 02:33:06 字数 249 浏览 7 评论 0原文

假设我有一个队列,多个消费者正在监听。我将一个请求放在队列中,其中一个消费者将处理它,并向我发送回复。

现在,假设我不耐烦,如果一段时间后没有回复,我会发出另一个请求。

在这种情况下,我可以重复使用相同的关联 ID 吗?如果回复不止一次,我会忽略多余的回复。

对我来说听起来很合理,但只是想仔细检查一下它是否不会扰乱 AMQP。

PS我正在使用RabbitMQ 2.4和rabbitmq-java-client 2.2

Let's say I have a queue on which multiple consumers are listening to. I put a request on the queue and one of the consumer will process it, and send me the reply.

Now, let's say I'm impatient and if the reply doesn't come after a while, I fire another request.

In this case, can I re-use the same correlation ID? If the reply comes more than once, I'd just ignore the extra reply.

Sounds reasonable enough to me, but just wanted to double check that it won't mess up AMQP in anyway.

P.S. I am using RabbitMQ 2.4 with rabbitmq-java-client 2.2

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

冰雪之触 2024-11-07 02:33:06

我有一种感觉,效果会很好。虽然我没有对 RpcClient 类做太多事情,但我相信它只是阻止等待相关回复消息出现在适当的回复队列中。因此,如果您从“客户端”应用程序中的另一个线程发出具有相同 ID 的另一个请求(导致相关回复最终出现),RpcClient 调用将返回。

当然,代理不会关心,因为它应该只将相关 ID 作为不透明的消息属性传递。

您应该注意,如果您的请求可以多次重新发出,那么您的请求就是幂等。成功的。

I have a feeling that will work fine. While I haven't done much with the RpcClient class, I believe it just blocks waiting for the correlated reply message to appear on the appropriate reply queue. Therefore if you fire another request with the same ID from another thread in your "client" app (causing the correlated reply to finally appear) the RpcClient call will return.

Certainly the broker won't care, as it should just pass the correlation ID along as an opaque message property.

You should take care that your requests are idempotent if they can be re-issued multiple times until they are successful.

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