You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by ben1729 <bm...@scottlogic.co.uk> on 2012/07/13 17:33:34 UTC
Splitting, processing and aggregating a list
Hi all,
I would like to take a message containing a list of objects, split the list
into it's component objects, process them in parallel, aggregate the
modified objects back into a list.
I am using camel 2.8.0.
>From what I can see I need to use a route in the following form:
from("jms:queue:from")
.split(Expression, AggregationStrategy) // What goes here?
.parallelProcessing()
// Processing goes here
.end()
.to("direct:end");
I think I can write the aggregation strategy but I'm unsure how to split the
list in the Expression. All the example seems to be with splitting strings.
Ben
--
View this message in context: http://camel.465427.n5.nabble.com/Splitting-processing-and-aggregating-a-list-tp5716013.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Splitting, processing and aggregating a list
Posted by yvesdm <yv...@gmail.com>.
I found this old post while I was trying to do same thing but using a class
that extends AbstractListAggregationStrategy to rebuild a List after the
completion of the split.
Using this aggregator way of doing, I found a problem : at the end of the
split, the body is not replaced by the agregated list ->
AbstractListAggregationStrategy.onCompletion(Exchange exchange) is never
called.
Here is what I do :
from(HANDLE_A_LIST)//
.split(body(), new ListAggregationStrategy())// body is an
arrayList of String
.to("log:foo")//
.end()// end split
// the body is a string instead of a List
.end()// end route
class ListAggregationStrategy extends
AbstractListAggregationStrategy<String>
{
@Override
public String getValue(Exchange exchange)
{
return exchange.getIn().getBody();
}
}
Is it a bug ?
As workaround, I use .setBody(property(Exchange.GROUPED_EXCHANGE)) after the
end of the split.
Kind Regards,
Yves.
--
View this message in context: http://camel.465427.n5.nabble.com/Splitting-processing-and-aggregating-a-list-tp5716013p5745127.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Splitting, processing and aggregating a list
Posted by ben1729 <bm...@scottlogic.co.uk>.
For anyone who finds this in future, this did the trick for me:
from(REQUEST_QUEUE_ENDPOINT)
.split(body(), new AggregationStrategy() {
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
if (oldExchange == null && newExchange != null) {
// Create list and add object to it. Set list as body to new exchange
return newExchange;
} else {
// Add object from new exchange to list on old exchange
return oldExchange;
}
}
})
.parallelProcessing()
// Procsesing goes here
.end()
.to(RESPONSE_QUEUE_ENDPOINT)
;
--
View this message in context: http://camel.465427.n5.nabble.com/Splitting-processing-and-aggregating-a-list-tp5716013p5716076.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Splitting, processing and aggregating a list
Posted by Vincent Nonnenmacher <vi...@gmail.com>.
On Fri, Jul 13, 2012 at 5:49 PM, Claus Ibsen <cl...@gmail.com> wrote:
> On Fri, Jul 13, 2012 at 5:45 PM, ben1729 <bm...@scottlogic.co.uk>
> wrote:
> > Claus to the rescue! Thank you very much, works like a charm. Nice book
> by
> > the way.
> >
>
> Ah if you got the book, then see chapter 8, section 8.3.2
>
> guess you made a small type Clauss,
you should have write :
Ah if you got *THE* book, then or (*ZEEEE* book)
but I guess you couldn't ;-), but I can, it is a must have for any Camel
user
Re: Splitting, processing and aggregating a list
Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Jul 13, 2012 at 5:45 PM, ben1729 <bm...@scottlogic.co.uk> wrote:
> Claus to the rescue! Thank you very much, works like a charm. Nice book by
> the way.
>
Ah if you got the book, then see chapter 8, section 8.3.2
> Ben
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Splitting-processing-and-aggregating-a-list-tp5716013p5716015.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Re: Splitting, processing and aggregating a list
Posted by ben1729 <bm...@scottlogic.co.uk>.
Claus to the rescue! Thank you very much, works like a charm. Nice book by
the way.
Ben
--
View this message in context: http://camel.465427.n5.nabble.com/Splitting-processing-and-aggregating-a-list-tp5716013p5716015.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Splitting, processing and aggregating a list
Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Jul 13, 2012 at 5:33 PM, ben1729 <bm...@scottlogic.co.uk> wrote:
> Hi all,
>
> I would like to take a message containing a list of objects, split the list
> into it's component objects, process them in parallel, aggregate the
> modified objects back into a list.
>
> I am using camel 2.8.0.
>
> From what I can see I need to use a route in the following form:
>
> from("jms:queue:from")
> .split(Expression, AggregationStrategy) // What goes here?
> .parallelProcessing()
> // Processing goes here
> .end()
> .to("direct:end");
>
> I think I can write the aggregation strategy but I'm unsure how to split the
> list in the Expression. All the example seems to be with splitting strings.
>
You can use a method call expression (also known as bean in the DSL),
and just return a List, or Iterator etc. that contains the bodies to
split. In newer releases of Camel, there is also a method to indicate
a method call expression.
.split(bean(MySplliterBean.class, AggregationStrategy) // What goes here?
And then just have a single public static method on the class. And you
can use the bean parameter binding for the method signature.
And then return a List / Iterator / etc.
> Ben
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Splitting-processing-and-aggregating-a-list-tp5716013.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen