A response over a one way bus
Messaging is naturally one way: fire a message and move on. But sometimes the caller needs an answer, like a price quote. Request reply layers a response onto the bus without turning it into a blocking call.
The mechanics
- The requester sends a message and includes two fields: a reply to address naming a queue where the answer should go, and a correlation id that uniquely tags this request.
- The responder does the work and publishes a reply to that reply to queue, copying the same correlation id.
- The requester listens on its reply queue and uses the correlation id to match each reply to the pending request that is waiting for it.
Why correlation id matters
Many requests are in flight at once, and replies can arrive out of order. The correlation id is what lets the requester pair reply with request. Without it, the requester could not tell whose answer is whose.
Tradeoffs
- You still need a timeout in case no reply ever comes.
- It adds latency versus a direct call, so use it when decoupling is worth more than raw speed.
Key idea
Request reply uses a reply to address and a correlation id so an asynchronous bus can return answers matched to the right caller.