O'Reilly logo

Just Spring Integration by Madhusudhan Konda

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Aggregators

The job of Aggregators is to assemble multiple messages to create a single parent message. They are the opposite of splitters, since they require information to begin and end a task. They have to maintain state for this reason. They also need to follow certain strategies to correlate the messages and release them after they are aggregated.

This is a complex task because all the messages of a set have to arrive before the aggregators can start work. Before we look at a complicated aggregation task, let’s consider a simple task based on default correlation and release strategies.

The TradeAggregator defined below is a simple aggregator whose job is to aggregate the incoming child Trades into a parent Trade.

public class TradeAggregator {

  public ITrade aggregateTrade(List<ITrade> childTrades) {
    ...
  }
}

This aggregator is declared using the following metadata:

<int:aggregator input-channel="in-channel" 
                output-channel="agg-channel"
                ref="tradeAggregator" 
                method="aggregateTrade">
</int:aggregator> 

<bean id="tradeAggregator"
  class="com.madhusudhan.jsi.flow.aggregator.TradeAggregator" />

<!-- Splitter that would cut the messages for aggregator to re-build -->
<int:splitter input-channel="in-channel" ref="customSplitter"
  output-channel="out-channel">
  </int:splitter>
 <bean id="customSplitter"
  class="com.madhusudhan.jsi.flow.splitter.CustomEncryptedTradeSplitter" />

The ref and method attributes define a specific method on the POJO to be invoked whenever the release strategy is fulfilled. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required