Aggregator

In some situations, we need to be able to combine the results of individual, but related, messages into a single one that also allows us to continue to process them as a whole message. For example, we might request flight information from multiple airlines and then combine the responses together to provide the consumer with their best options.

 

The Aggregator can be considered similar to a stateful filter that will be used to both collect and persist a series of individual messages, until all messages have been received, and then combine them into one completed message. Multiple messages will enter the Aggregator, but only a single message will be output.

Correlation Key

The Aggregator pattern is one of the most complex patterns that can be created and the logic it contains can be fairly complex. The logic that is used to weave these messages together is based upon the use of a correlation key. A correlation key is a value that can be defined in a business process (like a loan number), that provides a mechanism to link and route information about a specific business process instance (like a loan approval process).

 

Aggregator using XML DSL with Bean

In this example, we are using strategyRef parameter to refer to our bean and the strategyMethodName to refer to the method to invoke on the bean:

<route> <from uri="direct:input/> <aggregate strategyRef="myAggregator" strategyMethodName="append" completionSize="3"> <correlationExpression> <constant>true</constant> </correlationExpression> <to uri="output:result"/> </aggregate> </route>

Â