Processors in parallel mode

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Processors in parallel mode

Sachin
Hi ,

When we set parallel processing in a route, do all processors run in parallel or in sequence?
MY requirement is that i have 5-6 processors in my route and i want then to be executed in parallel even for a single message, how can i achieve this?

from("direct:endpoint")
                .throttle(Long.parseLong(routeParams.get(RouteParam.THROTTLE)))
                .setBody().body(PaymentRequest.class)
                 .parallelProcessing()
                 .thread(4)
                .setHeader(ORIGINAL_REQUEST).javaScript("request.body")
                .convertBodyTo(PaymentRequest.class)
               
                .process(processor1)
               
                .process(processor2)
               
                .process(processor3)
               
                .process(processor4)

.end()
Reply | Threaded
Open this post in threaded view
|

RE: Processors in parallel mode

Diether

You create a simple route for each processor and then use multicast or recipientlist
http://camel.apache.org/multicast.html

Something like this:
from("direct:endpoint")
                .throttle(Long.parseLong(routeParams.get(RouteParam.THROTTLE)))
                .setBody().body(PaymentRequest.class)
                 .parallelProcessing()
                 .thread(4)
                .setHeader(ORIGINAL_REQUEST).javaScript("request.body")
                .convertBodyTo(PaymentRequest.class)
              .multicast().parallelProcessing().to("direct:processor1route", "direct:processor2route");


from("direct:processor1route")
 .process(processor1) ;

from("direct:processor2route")
 .process(processor2) ;

And so on.



Van: Sachin [via Camel] [[hidden email]]

Verzonden: vrijdag 26 april 2013 14:26

To: Wuyts Diether

Onderwerp: Processors in parallel mode







Hi ,



When we set parallel processing in a route, do all processors run in parallel or in sequence?


MY requirement is that i have 5-6 processors in my route and i want then to be executed in parallel even for a single message, how can i achieve this?




from("direct:endpoint")

                .throttle(Long.parseLong(routeParams.get(RouteParam.THROTTLE)))

                .setBody().body(PaymentRequest.class)

                 .parallelProcessing()

                 .thread(4)

                .setHeader(ORIGINAL_REQUEST).javaScript("request.body")

                .convertBodyTo(PaymentRequest.class)

               

                .process(processor1)

               

                .process(processor2)

               

                .process(processor3)

               

                .process(processor4)



.end()







If you reply to this email, your message will be added to the discussion below:
http://camel.465427.n5.nabble.com/Processors-in-parallel-mode-tp5731613.html



To start a new topic under Camel - Users, email [hidden email]


To unsubscribe from Camel - Users,
click here.

NAML




Reply | Threaded
Open this post in threaded view
|

RE: Processors in parallel mode

Sachin
Thanks for reply.
Yeah i can do that but only constraint is that i have so many processors and it doesnt make much sense to convert them to routes. Is there any other way i can run my processors concurrently?
Reply | Threaded
Open this post in threaded view
|

RE: Processors in parallel mode

Diether
I haven't tested it, but perhaps you can do something like this:
from("direct:a").multicast().parallelProcessing().to("bean:processor1", "bean:processor2",....);

But then you'll have to create beans from all your processors.



Van: Sachin [via Camel] [ml-node+[hidden email]]
Verzonden: vrijdag 26 april 2013 15:51
To: Wuyts Diether
Onderwerp: RE: Processors in parallel mode

Thanks for reply.
Yeah i can do that but only constraint is that i have so many processors and it doesnt make much sense to convert them to routes. Is there any other way i can run my processors concurrently?


If you reply to this email, your message will be added to the discussion below:
http://camel.465427.n5.nabble.com/Processors-in-parallel-mode-tp5731613p5731617.html
To start a new topic under Camel - Users, email ml-node+[hidden email]
To unsubscribe from Camel - Users, click here.
NAML
Reply | Threaded
Open this post in threaded view
|

RE: Processors in parallel mode

Sachin
I will try it..Thanks
Reply | Threaded
Open this post in threaded view
|

RE: Processors in parallel mode

Diether
Have a look at: http://camel.apache.org/processor.html
If you use Spring with component scanning you can simply annotate your processors as a @Service or @component and then use .multicast("processor1", "processor2"); 
Or define all your processors in you context xml file.
But the annotation are probably the fastes way to do this.



Van: Sachin [via Camel] [ml-node+[hidden email]]
Verzonden: vrijdag 26 april 2013 16:08
To: Wuyts Diether
Onderwerp: RE: Processors in parallel mode

I will try it..Thanks


If you reply to this email, your message will be added to the discussion below:
http://camel.465427.n5.nabble.com/Processors-in-parallel-mode-tp5731613p5731621.html
To start a new topic under Camel - Users, email ml-node+[hidden email]
To unsubscribe from Camel - Users, click here.
NAML
Reply | Threaded
Open this post in threaded view
|

RE: Processors in parallel mode

Sachin
Thanks Diether, yeah i am using spring with package scanning with component and service annotations. That will be great if it's so simple.
Reply | Threaded
Open this post in threaded view
|

RE: Processors in parallel mode

Sachin
Actually it worked with component scanning and even to add more if we keep all processors in normal way after multicast and parallel processing, that works too.
from("direct:endpoint")

              multicast().
                 .parallelProcessing()
                .process(processor1)
                .process(processor2)
                 .process(processor3)
                .process(processor4)
           .end()