You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by javaCzar <jm...@mimictechnologies.com> on 2013/05/20 22:44:00 UTC

Enable disable routes at startup using Spring

Is there a way to get something like this to work:

<route autoStartup="${enableRoute}">

The value of the attribute is set to a valid parsible string representation
of a boolean (ie. "true" or "false") yet I keep getting the following error:

org.apache.camel.RuntimeCamelException:
org.apache.camel.FailedToCreateRouteException: Failed to create route
route8: Route[[From[quickfix:quickfix.cfg]] -> [Filter[s... because of Error
parsing [${enableRoute}] from property ${enableRoute} as a Boolean.

Any assistnace would be greatly appreciated.



--
View this message in context: http://camel.465427.n5.nabble.com/Enable-disable-routes-at-startup-using-Spring-tp5732852.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Enable disable routes at startup using Spring

Posted by javaCzar <jm...@mimictechnologies.com>.
Willem,

Thanks for the assist. To aid anyone else that might follow this trhead,
here is what I ended up implementing:

start applicaiton with something like -Denvironment=dev or 
-Denvironment=prod

main context xml uses:
<import resource="some-context-${environment}.xml"/>

to import either "some-context-dev.xml" or "some-context-prod.xml"

some-context-dev.xml defines:
<routeContext id="aContext" xmlns="http://camel.apache.org/schema/spring">
   
</routeContext>

and some-context-prod.xml defines:
<routeContext id="aContext" xmlns="http://camel.apache.org/schema/spring">
   
</routeContext>




--
View this message in context: http://camel.465427.n5.nabble.com/Enable-disable-routes-at-startup-using-Spring-tp5732852p5732975.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Enable disable routes at startup using Spring

Posted by Willem jiang <wi...@gmail.com>.
Hi,

How about importing routes from other XML files[1]?
You can put a dummy xml in you test resource directory which could be find first when you doing the POC or testing.
When you want to run the route in production, you just need to make sure the dummy one is not in the class path.

[1]http://camel.apache.org/spring.html#Spring-HowdoIimportroutesfromotherXMLfiles  

--  
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem





On Tuesday, May 21, 2013 at 10:28 PM, javaCzar wrote:

> Willem,
>  
> My error in the last post. Your assitance with the {{xxx}} naming was
> correct. The variable is being set correctly and can be accessed bia this
> naming.
>  
> I thought is was not working because what I am seeing that with
> "autoStartup=false" the endpoint still initializes, just the incoming data
> is not sent to the rest of the route.
>  
> So, I guess this brings me to a second question. Is there a way to not
> initialize the endpoint via configuration. The reason that I need is for the
> following. I have an endpoint (QuickFIXj) that should not be connecting in
> certain circumstances For example, testing and dev instances should not
> attemtp to connect to a FIX server via this endpoint. However, prod
> instances need to have this enabled.  
>  
> I would imagine that this scenario exixst for many connection based
> services/endpoints. Is there a way to configure the camelContext with what
> essentially would work like old school compiler derectives:
>  
> something along the lines of:  
>  
> <camelContext>
> <route>
> ....
> </route>
> #ifdef PROD
> <route>
> ....
> </route>
> #endif  
> </camelContext>
>  
> Again, I know this code above is not valid, just an example of what I would
> need it to work like. As if it was not even there when not in prod.
>  
> Thanks.
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/Enable-disable-routes-at-startup-using-Spring-tp5732852p5732911.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).




Re: Enable disable routes at startup using Spring

Posted by javaCzar <jm...@mimictechnologies.com>.
Willem,

My error in the last post. Your assitance with the {{xxx}} naming was
correct. The variable is being set correctly and can be accessed bia this
naming.

I thought is was not working because what I am seeing that with
"autoStartup=false" the endpoint still initializes, just the incoming data
is not sent to the rest of the route.

So, I guess this brings me to a second question. Is there a way to not
initialize the endpoint via configuration. The reason that I need is for the
following. I have an endpoint (QuickFIXj) that should not be connecting in
certain circumstances For example, testing and dev instances should not
attemtp to connect to a FIX server via this endpoint. However, prod
instances need to have this enabled. 

I would imagine that this scenario exixst for many connection based
services/endpoints. Is there a way to configure the camelContext with what
essentially would work like old school compiler derectives:

something along the lines of: 

<camelContext>
   <route>
      ....
   </route>
#ifdef PROD
   <route>
      ....
   </route>
#endif  
</camelContext>

Again, I know this code above is not valid, just an example of what I would
need it to work like. As if it was not even there when not in prod.

Thanks.



--
View this message in context: http://camel.465427.n5.nabble.com/Enable-disable-routes-at-startup-using-Spring-tp5732852p5732911.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Enable disable routes at startup using Spring

Posted by javaCzar <jm...@mimictechnologies.com>.
Willem,

I am loading the properties in a bean:

<bean id="propLoader" class="com.aaa.bbb.ccc.PropLoader"/>

public class PropLoader extends BridgePropertyPlaceholderConfigurer {
   ...
            Properties props = new Properties();
            for (String prop : myProperties.getPropertyNames()) {
                if (prop != null) {
                    // this loads the property "enableRoute" with value
"true" or "false"
                    props.setProperty(prop, myProperties.getValue(prop));
                }
            }
            super.setProperties(props);
   ...
}

this bean is in the depends-on for the camelContext:

<camelContext xmlns="http://camel.apache.org/schema/spring" trace="true"
depends-on="propLoader,otherbean">
   <route autoStartup="${enableRoute}">
   ...
   </route>
</camelContext>

I am basing this off of info from:

http://camel.apache.org/how-do-i-use-spring-property-placeholder-with-camel-xml.html

I tried to use the {{enableRoute}} naming you mentioned, and I no longer get
the exception; however, it does not seem to take because the route starts
regardless of the value I set. I'm pretty sure that {{enableRoute}} is not
getting the correct value that I am setting via the Spring
BridgePropertyPlaceholderConfigurer.

Thanks again for the assistance.

JC



--
View this message in context: http://camel.465427.n5.nabble.com/Enable-disable-routes-at-startup-using-Spring-tp5732852p5732907.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Enable disable routes at startup using Spring

Posted by Willem jiang <wi...@gmail.com>.
Hi,

How did you setup the property component?
I think you can not use the Spring property placeholder inside route definition.
But here is an example you can take a look.

<camelContext xmlns="http://camel.apache.org/schema/spring"> <propertyPlaceholder id="properties" location="org/apache/camel/my.properties"/>  
<route autoStartup="{{enableRoute}}">
……


--  
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem





On Tuesday, May 21, 2013 at 4:44 AM, javaCzar wrote:

> Is there a way to get something like this to work:
>  
> <route autoStartup="${enableRoute}">
>  
> The value of the attribute is set to a valid parsible string representation
> of a boolean (ie. "true" or "false") yet I keep getting the following error:
>  
> org.apache.camel.RuntimeCamelException:
> org.apache.camel.FailedToCreateRouteException: Failed to create route
> route8: Route[[From[quickfix:quickfix.cfg]] -> [Filter[s... because of Error
> parsing [${enableRoute}] from property ${enableRoute} as a Boolean.
>  
> Any assistnace would be greatly appreciated.
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/Enable-disable-routes-at-startup-using-Spring-tp5732852.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).