You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by boday <bo...@vektrel.com> on 2009/07/22 19:16:01 UTC

pass properties into SMX Camel Route

I need to dynamically configure some Camel route properties (http endpoint
URL, etc) based on a properties file.  What is the best way to do this?

I thought I could create a local.properties file and use Spring's
PropertyPlaceholderConfigurer, but I'm not sure how this works with Camel
DSL exactly...

here is what I have today...

local.properties file with a property "inboundURL=http://test.com"

MyRouteBuilder.java with a hardcoded URL

String inboundURL = "http://test.com"   //TODO: need to be from prop file
...
from("jetty:" + inboundURL)
.to("activemq:GatewayMsgQueue");
...

thanks

-----
Ben O'Day
Vektrel - Senior Consultant

-- 
View this message in context: http://www.nabble.com/pass-properties-into-SMX-Camel-Route-tp24610703p24610703.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: pass properties into SMX Camel Route

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Using ClassLoader.getResourceAsStream(), the file has to be in the 
classloader.

Basicly, you can add a new classpath entry in the servicemix startup 
script (for example etc/my-config and update the CLASSPATH).

Putting it in your project resources directory is not good as this 
properties file needs to be changed by the users I guess.

Regards
JB

boday wrote:
> that is what I was looking for...one last question, where would the
> "my.properties" file need to be located...or how would it be added to the
> path to be made available exactly...thanks again
> 
> 
> Jean-Baptiste Onofré wrote:
>> Ah OK Ben,
>>
>> using Java, you can construct the URIs by hand and provide in endpoint.
>>
>> For example, you can use system wide properties, or load a properties 
>> file from the classpath (or using Spring resource):
>>
>> Properties properties = new Properties();
>> properties.load(this.getClass().getClassLoader().getResourceAsStream("my.properties");
>> String route = properties.getProperty("route_endpoint");
>> String jbiEndpoint = "jbi:" + route:
>> from("timer:mytime").to(jbiEndpoint);
>>
>> in your RouteBuilder configure() method.
>>
>> I never tried this but it should work.
>>
>> Regards
>> JB
>>
>> boday wrote:
>>> thanks.  I saw this article earlier, but I'm using the Java DSL (not XML)
>>> to
>>> configure my routes.  How do I pass/access these properties from
>>> MyRouteBuilder.java file?
>>>
>>> Overall, are there other ways to get machine specific properties into SMX
>>> builds (System properties, etc) besides the Spring configuration?
>>>
>>>
>>> Jean-Baptiste Onofré wrote:
>>>> Hi Ben;
>>>>
>>>> Charles Mouillard from Camel has blog this:
>>>> http://cmoulliard.blogspot.com/2009/05/trick-to-pass-uri-declared-in-property.html
>>>>
>>>>
>>>
>>> -----
>>> Ben O'Day
>>> Vektrel - Senior Consultant
>>>
>> -- 
>> Jean-Baptiste Onofré (Nanthrax)
>> BuildProcess/AutoDeploy Project Leader
>> http://buildprocess.sourceforge.net
>> jb@nanthrax.net
>> PGP : 17D4F086
>>
>>
> 
> 
> -----
> Ben O'Day
> Vektrel - Senior Consultant
> 

-- 
Jean-Baptiste Onofré
---------------------------------
  HomePage
http://www.nanthrax.net
---------------------------------
  Contacts
jbonofre@apache.org
jb@nanthrax.net
---------------------------------
  OpenSource
BuildProcess/AutoDeploy
http://buildprocess.sourceforge.net
Apache ServiceMix
http://servicemix.apache.org
-----------------------------------
PGP : 17D4F086

Re: pass properties into SMX Camel Route

Posted by boday <bo...@vektrel.com>.
that is what I was looking for...one last question, where would the
"my.properties" file need to be located...or how would it be added to the
path to be made available exactly...thanks again


Jean-Baptiste Onofré wrote:
> 
> Ah OK Ben,
> 
> using Java, you can construct the URIs by hand and provide in endpoint.
> 
> For example, you can use system wide properties, or load a properties 
> file from the classpath (or using Spring resource):
> 
> Properties properties = new Properties();
> properties.load(this.getClass().getClassLoader().getResourceAsStream("my.properties");
> String route = properties.getProperty("route_endpoint");
> String jbiEndpoint = "jbi:" + route:
> from("timer:mytime").to(jbiEndpoint);
> 
> in your RouteBuilder configure() method.
> 
> I never tried this but it should work.
> 
> Regards
> JB
> 
> boday wrote:
>> thanks.  I saw this article earlier, but I'm using the Java DSL (not XML)
>> to
>> configure my routes.  How do I pass/access these properties from
>> MyRouteBuilder.java file?
>> 
>> Overall, are there other ways to get machine specific properties into SMX
>> builds (System properties, etc) besides the Spring configuration?
>> 
>> 
>> Jean-Baptiste Onofré wrote:
>>> Hi Ben;
>>>
>>> Charles Mouillard from Camel has blog this:
>>> http://cmoulliard.blogspot.com/2009/05/trick-to-pass-uri-declared-in-property.html
>>>
>>>
>> 
>> 
>> -----
>> Ben O'Day
>> Vektrel - Senior Consultant
>> 
> 
> -- 
> Jean-Baptiste Onofré (Nanthrax)
> BuildProcess/AutoDeploy Project Leader
> http://buildprocess.sourceforge.net
> jb@nanthrax.net
> PGP : 17D4F086
> 
> 


-----
Ben O'Day
Vektrel - Senior Consultant

-- 
View this message in context: http://www.nabble.com/pass-properties-into-SMX-Camel-Route-tp24610703p24611927.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: pass properties into SMX Camel Route

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Ah OK Ben,

using Java, you can construct the URIs by hand and provide in endpoint.

For example, you can use system wide properties, or load a properties 
file from the classpath (or using Spring resource):

Properties properties = new Properties();
properties.load(this.getClass().getClassLoader().getResourceAsStream("my.properties");
String route = properties.getProperty("route_endpoint");
String jbiEndpoint = "jbi:" + route:
from("timer:mytime").to(jbiEndpoint);

in your RouteBuilder configure() method.

I never tried this but it should work.

Regards
JB

boday wrote:
> thanks.  I saw this article earlier, but I'm using the Java DSL (not XML) to
> configure my routes.  How do I pass/access these properties from
> MyRouteBuilder.java file?
> 
> Overall, are there other ways to get machine specific properties into SMX
> builds (System properties, etc) besides the Spring configuration?
> 
> 
> Jean-Baptiste Onofré wrote:
>> Hi Ben;
>>
>> Charles Mouillard from Camel has blog this:
>> http://cmoulliard.blogspot.com/2009/05/trick-to-pass-uri-declared-in-property.html
>>
>>
> 
> 
> -----
> Ben O'Day
> Vektrel - Senior Consultant
> 

-- 
Jean-Baptiste Onofré (Nanthrax)
BuildProcess/AutoDeploy Project Leader
http://buildprocess.sourceforge.net
jb@nanthrax.net
PGP : 17D4F086

Re: pass properties into SMX Camel Route

Posted by boday <bo...@vektrel.com>.
thanks.  I saw this article earlier, but I'm using the Java DSL (not XML) to
configure my routes.  How do I pass/access these properties from
MyRouteBuilder.java file?

Overall, are there other ways to get machine specific properties into SMX
builds (System properties, etc) besides the Spring configuration?


Jean-Baptiste Onofré wrote:
> 
> Hi Ben;
> 
> Charles Mouillard from Camel has blog this:
> http://cmoulliard.blogspot.com/2009/05/trick-to-pass-uri-declared-in-property.html
> 
> 


-----
Ben O'Day
Vektrel - Senior Consultant

-- 
View this message in context: http://www.nabble.com/pass-properties-into-SMX-Camel-Route-tp24610703p24611267.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: pass properties into SMX Camel Route

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi Ben;

Charles Mouillard from Camel has blog this:
http://cmoulliard.blogspot.com/2009/05/trick-to-pass-uri-declared-in-property.html

Anyway, if you can use property directly into Camel URIs, you can use 
endpoint definition like this:
<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
        http://activemq.apache.org/camel/schema/spring 
http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
     ">

   <bean 
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/> 


   <camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
     <endpoint id="input1" uri="activemq:${someQueueName}"/>

     <route>
       <from ref="input1"/>
       <to uri="activemq:OutputQueue"/>
     </route>
   </camelContext>


</beans>

Regards
JB

boday wrote:
> I need to dynamically configure some Camel route properties (http endpoint
> URL, etc) based on a properties file.  What is the best way to do this?
> 
> I thought I could create a local.properties file and use Spring's
> PropertyPlaceholderConfigurer, but I'm not sure how this works with Camel
> DSL exactly...
> 
> here is what I have today...
> 
> local.properties file with a property "inboundURL=http://test.com"
> 
> MyRouteBuilder.java with a hardcoded URL
> 
> String inboundURL = "http://test.com"   //TODO: need to be from prop file
> ...
> from("jetty:" + inboundURL)
> .to("activemq:GatewayMsgQueue");
> ...
> 
> thanks
> 
> -----
> Ben O'Day
> Vektrel - Senior Consultant
> 

-- 
Jean-Baptiste Onofré (Nanthrax)
BuildProcess/AutoDeploy Project Leader
http://buildprocess.sourceforge.net
jb@nanthrax.net
PGP : 17D4F086