how to do Aggregator Pattern in akka for java

523 views
Skip to first unread message

simaf...@gmail.com

unread,
Jun 23, 2014, 11:32:08 PM6/23/14
to akka...@googlegroups.com
Hi All,

In camel there is aggregate pattern. 

Sample code as below
<aggregate strategyRef="aggregatorStrategy"
completionInterval="5000" completionSize="100" forceCompletionOnStop="true">
<correlationExpression>
<simple>header.aggregatorId</simple>
</correlationExpression>
                        <to uri="testProcessor"/>
</aggregate>

Somebody could tell me how  to use akka-camel to implement aggregate  in java? thanks

Michael Pisula

unread,
Jun 24, 2014, 5:01:17 AM6/24/14
to akka...@googlegroups.com
Hi,

When using akka-camel, I try to use only the camel endpoints and rely on akka for everything else. This way you get all the benefits of both worlds, the awesome amount of endpoints camel can connect to, and the nice programming model and powerful concepts Akka provides. For aggregation there is currently a pattern in the contrib package (http://doc.akka.io/docs/akka/2.3.0/contrib/aggregator.html), however it is only available in Scala. You can build an aggregator yourself though, and it is not that hard. After all you can model this using one actor which will receive all messages that need to be aggregated. You need to provide a timeout to handle failures, and have can handle everything as you like. This is a much more flexible approach. The Akka In Action book by Ray Roestenburg (http://www.manning.com/roestenburg/), currently available as a preview, contains a possible implementation of an aggregator (in scala again, but easily transferable to Akka).

It is worth mentioning that you can still use camel routes when using akka-camel. The two actors provided by akka-camel, Producer and Consumer, are the points at which you connect the camel and the akka world. BUT, I would avoid putting too much of your logic into the camel part, like written before, I think the main benefit of akka-camel is that you can make use of the camel endpoints. Everything else I would do in Akka.

HTH

Cheers,
Michael
Reply all
Reply to author
Forward
0 new messages