Aggregation according to size or predicate as described in the Aggregating related messages recipe is an excellent foundation for batching messages together. This recipe will describe how to use timeouts to release an aggregated message if no additional exchanges have been received for aggregation in a while.
The Java code for this recipe is located in the org.camelcookbook.splitjoin.aggregatetimeouts
package. The Spring XML example is located in src/main/resources/META-INF/spring/aggregateCompletionTimeout-context.xml
.
Inside your Aggregator definition, add a completionTimeout
attribute containing a timeout in milliseconds. The attribute can be used as the sole aggregation condition, or in combination with others.
In the XML DSL, this is written as:
<from uri="direct:in"/>
<aggregate strategyRef="setAggregationStrategy"
completionSize="10"
completionTimeout="1000">
<correlationExpression>
...