camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Citizen <>
Subject problems with Camel aggregation pattern
Date Fri, 05 Aug 2011 13:55:55 GMT

I'm using Camel version 2.8.0.
I have a file with rows consisting of two columns: parent, child. Both are
strings. Example:

I wrote a custom AggregationStrategy class that groups child values into a
single collection, based on the parent. My aggregate(Exchange
oldExchange,Exchange newExchange) method looks like this:

 if (oldExchange == null) {
  parent = new Map();
 } else {
  parent = (Map) oldExchange.getIn().getBody();
 //put child into map
 return oldExchange == null ? newExchange : oldExchange;

Messages are correlated based on parent column. CompletionPredicate is coded
like this:

 //instance variable lastParent;

 matches(Exchange exchange) {
  tuple= exchange.getIn().getBody();

  if (lastParent == null) { //first record, no history
   lastParent = tuple.parent;
   return false;
  } else if (lastParent.equals(tuple.parent)) { //same parent, part of batch
   return false;

  lastParent = tuple.parent; //different parent, new batch
  return true;

My Camel route looks something like this:

from("direct:input").aggregate(parentCorrelation, myAggregationStrategy)


The code works as expected to a point. Child columns are grouped into single
map, based on the parent column. But the first map produced by the
aggregator is skipped (it is not delivered to the processor), and subsequent
maps delivered to the processor contain only one entry (the first child

So the steps look something like this:

//last step for first batch
- adding map to repository, map contains 3 children, parent is parent1
- completion predicate kicks in since parent2 is different from parent1
- map for parent2 is removed from repository and sent to processor (map
contains only one entry)
- new map is created for parent2
- processing continues

I think this behavior is related to how aggregationStrategy and
completionPredicate work together.
If anyone has had to deal with such scenario in the past I'd appreciate any
info on how to make it work?


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

View raw message