camel-users mailing list archives

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

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

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();
  newExchange.getIn().setBody(parent);
 } 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)

.aggregationRepository(repository).completionPredicate(myCompletionPredicate)
 .process(myProcessor).to("direct:output");


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
column).

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?
Thanks,

Mark




--
View this message in context: http://camel.465427.n5.nabble.com/problems-with-Camel-aggregation-pattern-tp4669621p4669621.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Mime
View raw message