You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by JacobS <ja...@gmail.com> on 2011/03/22 22:20:42 UTC

Add a Processor to a route at runtime

Hi

Is it possible to alter an existing running route and add a Processor to
some point at the routes sequence using the camel api ? 

something like :

Route route = camelContext.getRoute(routeID);
route.suspend();
route.addProcessor(new SomeProcessor());
route.resume();

If it is possible please post a simple example.

Thanks,
Jacob

--
View this message in context: http://camel.465427.n5.nabble.com/Add-a-Processor-to-a-route-at-runtime-tp4257724p4257724.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Add a Processor to a route at runtime

Posted by JacobS <ja...@gmail.com>.
Thank you very much

--
View this message in context: http://camel.465427.n5.nabble.com/Add-a-Processor-to-a-route-at-runtime-tp4257724p4267611.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Add a Processor to a route at runtime

Posted by Claus Ibsen <cl...@gmail.com>.
Look at the unit of work on the exchange as it contains message
history details. In rhe the current route id as well.

On Monday, March 28, 2011, JacobS <ja...@gmail.com> wrote:
> Thanks the java predicate works but I still have  problem identifying  the
> route that is being checked for interception.
> I tried using the 'exchange.getFromEndpoint().getEndpointUri()' but this
> only returns the endpoint which originated this message exchange .
> Is there a way to get the RouteId in the predicate ?
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Add-a-Processor-to-a-route-at-runtime-tp4257724p4267538.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
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: Add a Processor to a route at runtime

Posted by JacobS <ja...@gmail.com>.
Thanks the java predicate works but I still have  problem identifying  the
route that is being checked for interception. 
I tried using the 'exchange.getFromEndpoint().getEndpointUri()' but this
only returns the endpoint which originated this message exchange .
Is there a way to get the RouteId in the predicate ?

--
View this message in context: http://camel.465427.n5.nabble.com/Add-a-Processor-to-a-route-at-runtime-tp4257724p4267538.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Add a Processor to a route at runtime

Posted by Claus Ibsen <cl...@gmail.com>.
Just use java code to build a custom Predicate that computes this, and
use it with the onWhen on the interceptor.


On Wed, Mar 23, 2011 at 9:56 AM, JacobS <ja...@gmail.com> wrote:
> Looks like interceptFrom could be the right way to go.
> How can I add a predicate to the interceptFrom that will intercept according
> to a header and the routeID ?
> Something like this:
>
>
>
>
>                ${in.getExchange.getFromRouteId} == ${in.header.interceptFromRouteID} />
>
>
>
> except I am getting 'Illegal syntax: in.getExchange.getFromRouteId'
> excpetion.
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Add-a-Processor-to-a-route-at-runtime-tp4257724p4258424.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
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: Add a Processor to a route at runtime

Posted by JacobS <ja...@gmail.com>.
Looks like interceptFrom could be the right way to go.
How can I add a predicate to the interceptFrom that will intercept according
to a header and the routeID ?
Something like this:


	
	
		${in.getExchange.getFromRouteId} == ${in.header.interceptFromRouteID} />
	


except I am getting 'Illegal syntax: in.getExchange.getFromRouteId'
excpetion.

--
View this message in context: http://camel.465427.n5.nabble.com/Add-a-Processor-to-a-route-at-runtime-tp4257724p4258424.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Add a Processor to a route at runtime

Posted by Willem Jiang <wi...@gmail.com>.
On 3/23/11 3:07 PM, JacobS wrote:
> I am adding plugins functionality to my app and I want the plugins to be able
> to add processors to the existing routes. I don't know in which route or
> where in the route the plugin would want to add some logic thats why I
> wanted to add the processors at runtime.

It's hard the find a right place to add your processor unless you tell 
camel exactly the place that you want to add the processor.
And the intercept is adding the processor when it loads routes, I don't 
think you can do it in the runtime unless you stop the route and start a 
new one for it.
>
> Can 'Camel Intercept' help me with this ?
> -Is it possible to add intercepts at run-time to a chosen location ?
Intercepts supports to add processors at the endpoint that match your 
requirement. And it also supports to do the intercepts which is based on 
the exchange.

> -How would it effect performance if I add intercepts to all routes before
> each processing step although I wont be needing added functionality to all
> of the processing steps?
That would be a problem, I don't suggest your add the intercepts into 
all the route. If you really need to do that, you may consider to stop 
the camel context and use some kind of option to decide if enable the 
intercepts or not.

>
> Thanks
> Jacob
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Add-a-Processor-to-a-route-at-runtime-tp4257724p4258285.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>


-- 
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
          http://jnn.javaeye.com (Chinese)
Twitter: willemjiang

Re: Add a Processor to a route at runtime

Posted by JacobS <ja...@gmail.com>.
I am adding plugins functionality to my app and I want the plugins to be able
to add processors to the existing routes. I don't know in which route or
where in the route the plugin would want to add some logic thats why I
wanted to add the processors at runtime.

Can 'Camel Intercept' help me with this ?
-Is it possible to add intercepts at run-time to a chosen location ?
-How would it effect performance if I add intercepts to all routes before
each processing step although I wont be needing added functionality to all
of the processing steps?

Thanks
Jacob

--
View this message in context: http://camel.465427.n5.nabble.com/Add-a-Processor-to-a-route-at-runtime-tp4257724p4258285.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Add a Processor to a route at runtime

Posted by "Willem.Jiang" <wi...@gmail.com>.
Can I know why you want to add Processor into the route?
I don't think current Camel provides that kind of API you want.

You may consider to use this handy Intercept[1] of Camel instead of add the
processor to the route. 

[1]http://camel.apache.org/intercept.html

Willem

JacobS wrote:
> 
> Hi
> 
> Is it possible to alter an existing running route and add a Processor to
> some point at the routes sequence using the camel api ? 
> 
> something like :
> 
> Route route = camelContext.getRoute(routeID);
> route.suspend();
> route.addProcessor(new SomeProcessor());
> route.resume();
> 
> If it is possible please post a simple example.
> 
> Thanks,
> Jacob
> 

--
View this message in context: http://camel.465427.n5.nabble.com/Add-a-Processor-to-a-route-at-runtime-tp4257724p4258152.html
Sent from the Camel - Users mailing list archive at Nabble.com.