Problem
A caller needs a result from a service that is slow, scaled independently or reachable only via messaging. Holding an HTTP connection or blocking a thread wastes resources and fails on timeouts.
Also known as: asynchronous request-reply, RPC over messaging
Get a response to a request using asynchronous queues, with a correlation id linking the reply to the original request.
A caller needs a result from a service that is slow, scaled independently or reachable only via messaging. Holding an HTTP connection or blocking a thread wastes resources and fails on timeouts.
Request-reply layers a conversation on one-way messaging. Each side needs only the broker, not the other side address.
The correlation id is the essential piece. Without it a requester with many in-flight calls cannot tell which reply is which.
Decide how the caller experiences the wait. A synchronous wrapper blocks until the reply or timeout, which is convenient but ties up a thread. An asynchronous style returns a ticket at once and delivers the result by callback, polling endpoint or notification, which scales better for slow work.
The requester registers a pending entry under a fresh correlation id, publishes the request, and a reply listener completes the entry when a matching reply arrives.
req = {id: "c-91", replyTo: "replies.svcA", body: ...}
send("pricing.requests", req)
# responder
send(req.replyTo, {id: req.id, result: ...})
# requester listener
pending.pop("c-91").complete(result)
On the responder side, check the expiry before starting, since a request that waited in a long queue may already be useless. For idempotency, key the response by correlation id so a redelivered request returns the same answer instead of redoing the work. Include an error reply shape so failures arrive as messages rather than as silent timeouts.
Medium - broker and reply queues
Medium - queue cleanup and timeouts
Medium - correlation and timeout handling
Late reply arrives after the requester gave up
Reply queues leak when requesters die
Responder processes an expired request wastefully