Dynamic Scatter-Gather Example
In this example we want to get the best quote for beer from several different vendors. We use a dynamic Recipient List to get the request for a quote to all vendors and an Aggregator to pick the best quote out of all the responses. The routes for this are defined as:
So in the first route you see that the Recipient List is looking at the
This message will be distributed to the following Endpoints:
and are loaded up in Spring like
Each bean is loaded with a different price for beer. When the message is sent to each bean endpoint, it will arrive at the
At the next step we want to take the beer quotes from all vendors and find out which one was the best (i.e. the lowest!). To do this we use an Aggregator with a custom aggregation strategy. The Aggregator needs to be able to compare only the messages from this particular quote; this is easily done by specifying a correlationExpression equal to the value of the quoteRequestId header. As shown above in the message sending snippet, we set this header to
Finally, we expect to get the lowest quote of $1 out of $1, $2, and $3.
You can find the full example source here:
Static Scatter-Gather Example
You can lock down which recipients are used in the Scatter-Gather by using a static Recipient List. It looks something like this
A full example of the static Scatter-Gather configuration can be found in the Loan Broker Example.
Using This Pattern
If you would like to use this EIP Pattern then please read the Getting Started, you may also find the Architecture useful particularly the description of Endpoint and URIs. Then you could try out some of the Examples first before trying this pattern out.