Interface AggregationStrategy

All Known Subinterfaces:
CompletionAwareAggregationStrategy, OptimisticLockingAwareAggregationStrategy, TimeoutAwareAggregationStrategy
All Known Implementing Classes:
AbstractListAggregationStrategy, AggregationStrategyBeanAdapter, FlexibleAggregationStrategy, GroupedExchangeAggregationStrategy, UseLatestAggregationStrategy, UseOriginalAggregationStrategy

public interface AggregationStrategy

A strategy for aggregating two exchanges together into a single exchange.

On the first invocation of the aggregate method the oldExchange parameter is null. The reason is that we have not aggregated anything yet. So its only the newExchange that has a value. Usually you just return the newExchange in this situation. But you still have the power to decide what to do, for example you can do some alternation on the exchange or remove some headers. And a more common use case is for instance to count some values from the body payload. That could be to sum up a total amount etc.

It is possible that newExchange is null which could happen if there was no data possible to acquire. Such as when using a PollEnricher to poll from a JMS queue which is empty and a timeout was set.

Possible implementations include performing some kind of combining or delta processing, such as adding line items together into an invoice or just using the newest exchange and removing old exchanges such as for state tracking or market data prices; where old values are of little use.

If an implementation also implements Service then any EIP that allowing configuring a AggregationStrategy will invoke the Service.start() and Service.stop() to control the lifecycle aligned with the EIP itself.


Method Summary
 Exchange aggregate(Exchange oldExchange, Exchange newExchange)
          Aggregates an old and new exchange together to create a single combined exchange

Method Detail


Exchange aggregate(Exchange oldExchange,
                   Exchange newExchange)
Aggregates an old and new exchange together to create a single combined exchange

oldExchange - the oldest exchange (is null on first aggregation as we only have the new exchange)
newExchange - the newest exchange (can be null if there was no data possible to acquire)
a combined composite of the two exchanges

Apache Camel