Suresh Rohan's Blog

This blog is all about Java, J2EE,Spring, Angular, React JS, NoSQL, Microservices, DevOps, BigData, Tutorials, Tips, Best practice, Interview questions, Views, News, Articles, Techniques, Code Samples, Reference Application and much more

Friday, October 16, 2015

Pattern: Scatter-Gather



Pattern: Scatter-Gather

How do you maintain the overall message flow when a message needs to be sent to multiple recipients, each of which may send a reply?

Use a Scatter-Gather that broadcasts a message to multiple recipients and re-aggregates the
responses back into a single message.


The Scatter-Gather routes a request message to the a number of recipients. It then uses an Aggregator to collect the responses and distill them into a single response message.

There are two variants of the Scatter-Gather that use different mechanisms to send the request messages to the intended recipients:

  • Distribution via a Recipient List allows the Scatter-Gather to control the list of recipients but requires the Scatter-Gather to be aware of each recipient's message channel.
  • Auction-style Scatter-Gathers use a Publish-Subscribe Channel to broadcast the request to any interested participant. This option allows the Scatter-Gather to use a single channel but at the same time relinquishes control.

Example: Combining Patterns

We can now use the Scatter-Gather to implement the widget and gadget order processing example. We can combine the Scatter-Gather with the Composed Message Processor to process each incoming
order, sequence it into individual items, then pass each item up for a bid, then aggregate the bids
for each item into a combined bid response, and lastly aggregate all bid responses into a complete
quote. This is a very real example how multiple integration patterns can be combined into a
complete solution. The composition of individual patterns into larger patterns allows us to
discuss the solution at a higher level of abstraction. It also allows us to modify details of the
implementation without affecting other components.



No comments:

Post a Comment