Search code examples
rabbitmqamqp

May I use the same correlation ID in AMQP more than once?


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


Solution

  • 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.