Its easy to use a custom aggregator than try to do with DSL.
See http://camel.apache.org/aggregator2
As an example:
public class ListAggregationStrategy<T> implements AggregationStrategy {
/** The comparator used to keep the list sorted if any. */
final Comparator<T> comparator;
/**
* @param comparator The comparator used to keep the list sorted if any;
if this is null then the list will not be kept sorted.
*/
public ListAggregationStrategy(final Comparator<T> comparator) {
this.comparator = comparator;
}
@Override
public Exchange aggregate(final Exchange aggregatedExchange, final
Exchange newExchange) {
final T newBody = (T) newExchange.getIn().getBody();
List<T> exchangeBodies = null;
if (aggregatedExchange == null) {
exchangeBodies = new LinkedList<>();
exchangeBodies.add(newBody);
newExchange.getIn().setBody(exchangeBodies);
return newExchange;
}
exchangeBodies = aggregatedExchange.getIn().getBody(List.class);
exchangeBodies.add(newBody);
if (null != this.comparator) Collections.sort(exchangeBodies,
this.comparator);
return aggregatedExchange;
}
}
*Robert Simmons Jr. MSc. - Lead Java Architect @ EA*
*Author of: Hardcore Java (2003) and Maintainable Java (2012)*
*LinkedIn: **http://www.linkedin.com/pub/robert-simmons/40/852/a39
<http://www.linkedin.com/pub/robert-simmons/40/852/a39>*
On Tue, Feb 25, 2014 at 4:24 AM, Jens Breitenstein <[email protected]>wrote:
> Hi
>
> we aggragate all messages having the same key like this:
>
> .aggregate(new GroovyExpression("exchange.in.body.InstrumentID"),
> new QuoteAggregationStrategy())
>
> and get a List as result ("isStoreAsBodyOnCompletion() returns true").
>
> The QuoteAggregationStrategy is required to implement the abstract method
> <T> getValue(final Exchange exchange) to convert the message to a specific
> type.
> In case you do not have a aggregateble key you can have a look at
> AbstractListAggregationStrategy and all derived classes, maybe one fits
> because you need some state to keep track about the number of exchanges
> combined and the desired chunk size. Maybe you create your own aggregator
> derived from AbstractListAggregationStrategy and override this method:
>
> public Exchange aggregate(Exchange oldExchange, Exchange newExchange)
>
> ?
>
> Jens
>
>
>
> Am 25.02.14 10:11, schrieb tharangage:
>
> I am having another issue based on same solution given by "dulanov".
>> Is it possible to group N lines together?
>>
>> I come up with solution as follow without aggregation, but it is better
>> if i
>> can use aggregation as describe in this post. Can anyone please help on
>> this?
>>
>> from("file:/temp/test").split().tokenize("\n", 100).process(new
>> MyProcessor()).to("file:/home/test/dest?fileExist=Append");
>>
>>
>>
>>
>> --
>> View this message in context: http://camel.465427.n5.nabble.
>> com/How-to-aggregate-all-messages-into-a-single-
>> message-tp477603p5747917.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>
>