camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From huntc <>
Subject RE: How to use Aggregator and AggregationCollection?
Date Tue, 07 Oct 2008 11:34:30 GMT

Thanks to the help of Claus, I have discovered that I can use my own
aggregation strategy to collect all files into an Exchange containing a
collection of Exchanges. Here is my route building:

public class RouteBuilder extends org.apache.camel.builder.RouteBuilder {
	public void configure() {
			.aggregator(new CollectAllAggregationStrategy()).constant(true)
			.process(new Processor() {
				public void process(Exchange e) {
					System.out.println("Received exchange: "
							+ e.getIn().getBody());

...and here is my aggregation strategy:


public class CollectAllAggregationStrategy implements AggregationStrategy {

	public Exchange aggregate(Exchange arg0, Exchange arg1) {
		// If our previous exchange holds a collection of Exchanges then we
		// simply add to that collection. Otherwise we create a new Exchange
		// containing a collection of exchanges and use this for future
		// aggregations (and of course add to it presently).
		Collection collection;
		Object body = arg0.getIn().getBody();
		if (body instanceof Collection) {
			collection = (Collection) body;
		} else {
			collection = new Vector();

			Exchange newExchange = new DefaultExchange(arg0.getContext());
			Message in = new DefaultMessage();

			arg0 = newExchange;
		return arg0;

All exchanges appear to be bundled together given the use of the constant

I hope that others find this use of aggregation useful.

Kind regards,
View this message in context:
Sent from the Camel - Users mailing list archive at

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message