You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Claus Ibsen <cl...@gmail.com> on 2013/03/01 07:53:48 UTC
Re: AggregationStrategy not writing to end result
On Thu, Feb 28, 2013 at 7:59 PM, Gvvenkat <Gv...@yahoo.com> wrote:
> Hi,
> I am using an aggregator to add ";" inbetween the message that is
> tokenized by "\n". But the end result does not show ';' at the end every
> line.. what am I doing wrong..
>
> Here is route config...
> <route>
> <from uri="file:{{splitInBox}}" />
> <log message="spliting the message using tokenizer(\n) from splitInBox to
> splitOutBox. filename ${header.CamelFileName}" />
> <split streaming="true" strategyRef="splitNewLineStrategy" >
> <tokenize token="\n"/>
> <to uri="file:{{splitOutBox}}" />
> </split>
> <log message="Split completed" />
>
> </route>
>
See this pattern, as this is what you do
http://camel.apache.org/composed-message-processor.html
So the aggregation strategy merges the message to 1 outgoing message,
eg what comes after </split>.
Which in your case, you just log split completed.
>
> Here is the AggregationStrategy implemention.
>
> public class SplitLineStrategy implements AggregationStrategy {
>
> private static Logger log = Logger.getLogger(SplitLineStrategy.class);
>
> public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
> // put order together in old exchange by adding the order from new
> exchange
>
> if (oldExchange == null) {
> // the first time we aggregate we only have the new exchange,
> // so we just return it
> return newExchange;
> }
>
> String orders = oldExchange.getIn().getBody(String.class) + "\n";
> String newLine = newExchange.getIn().getBody(String.class);
>
> log.debug("Aggregate old orders: " + orders);
> log.debug("Aggregate new order: " + newLine);
>
> // put orders together separating by semi colon
> orders = orders + ";" +newLine;
> // put combined order back on old to preserve it
> oldExchange.getIn().setBody(orders);
>
> log.info(" aggregator returns " + orders);
>
> // return old as this is the one that has all the orders gathered
> until now
> return oldExchange;
> }
> }
>
>
> Any help will be great..
>
> Thanks a lot.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/AggregationStrategy-not-writing-to-end-result-tp5728317.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
--
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen