Since we're on a major migration process of this website, some component documents here are out of sync right now. In the meantime you may want to look at the asciidoc in the repository:

Aggregate Example

Available as of Camel 2.3


This example demonstrates the new overhauled Aggregator EIP in Apache Camel 2.3. The example is focused on the persistence support, which means the aggregated messages is stored in a persistent file storage using the new HawtDB component.

How to run

You simply run it using the following maven goal: mvn camel:run

How it works

The example is an interactive example where it prompt on the console for you to enter a number and press ENTER. The numbers you enter will then be aggregated and persisted. That means you can at any time hit ctrl + c to shutdown Camel. Then you should be able to start the example again and resume where you left.

When you want to complete the aggregation you can enter STOP as input and Camel will show you the result, which is the sum of all the numbers entered.

The persistent datastore is located in the data/hawtdb.dat file. Its automatic created the first time.


For example we start the example for the first time using mvn camel:run and then we enter the two numbers 5 and 7 before we shutdown using ctrl + c. The relevant console output:

Now we start the example again using mvn camel:run and enter the number 3 and then enter STOP to see the result. As expected the result is 5+7+3 = 15 as outputted on the console. As you can see the persistence of the aggregated messages ensures we could continue where we stopped.

Using Aggregator

The example is configured as follows in Spring XML.

And it has a AggregationStrategy to sum the numbers which is done in Java code as:

See Also

© 2004-2015 The Apache Software Foundation.
Apache Camel, Camel, Apache, the Apache feather logo, and the Apache Camel project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.
Graphic Design By Hiram