Request/Reply Patterns
Learn how to implement a Request/Reply pattern on top of a simple point-to-point one-way asynchronous channel.
One-way communications can give us great advantages in terms of parallelism and efficiency, but alone, they’re not able to solve all our integration and communication problems. Sometimes, a good old Request/Reply pattern might just be the perfect tool for the job. But, there are situations in which all we have is an asynchronous one-way channel. It’s therefore important to know the various patterns and approaches required to build an abstraction that would allow us to exchange messages in a request/reply fashion on top of a one-way channel. That’s exactly what we’re going to learn here.
Correlation Identifier
The first Request/Reply pattern that we’re going to learn is called the Correlation Identifier and it represents the basic block for building a request/reply abstraction on top of a one-way channel.
The pattern involves marking each request with an identifier, which is then attached to the response by the receiver: this way, the sender of the request can correlate the two messages and return the response to the right handler. This elegantly solves the problem in the context of a one-way asynchronous channel, where messages can travel in any direction at any time. Let’s take a look at an example in the following illustration.
Get hands-on with 1400+ tech skills courses.