You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by davsclaus <ci...@yahoo.dk> on 2011/04/30 09:18:24 UTC
Re: Agraggator to merge files
Yes that is possible.
Check out this wiki page
http://camel.apache.org/aggregator2
You may want to use the completionFromBatchConsumer=true to let the
aggregator pickup the X number of files from the directory. Then you have
that as a List.
Alternative you can use the aggregator to "merge" the files together to a
single message.
How to use the aggregator is extensively covered in the Camel in Action book
chapter 8. In fact I suggest you peak at some of the sample codes from the
book.
http://code.google.com/p/camelinaction/source/browse/#svn%2Ftrunk%2Fchapter8%2Faggregator%253Fstate%253Dclosed
-----Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/--
View this message in context: http://camel.465427.n5.nabble.com/Agraggator-to-merge-files-tp4358984p4360747.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Agraggator to merge files
Posted by davsclaus <ci...@yahoo.dk>.
The code can be something like this. Where we + the bodies together and use a
\n between them. But the code can be anything you like. Just set the
"result" on the IN body on the oldExchange and return it.
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
if (newExchange == null) {
return oldExchange;
}
String oldTxt = oldExchange.getIn().getBody(String.class);
String newTxt = newExchange.getIn().getBody(String.class);
String body = oldTxt + "\n" + newTxt;
// replace and return oldExchange
oldExchange.getIn().setBody(body);
return oldExchange;
}
-----
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/
--
View this message in context: http://camel.465427.n5.nabble.com/Agraggator-to-merge-files-tp4358984p4364111.html
Sent from the Camel - Users mailing list archive at Nabble.com.