You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by CharlieD <di...@gmail.com> on 2013/02/05 19:13:00 UTC
Reference OSGI Blueprint java.util.Properties service in Blueprint
Camel property placeholder
I want to have centralized shared properties (shared across camel contexts)
to define things, particularly ActiveMQ endpoints. Furthermore, I want to
avoid using /etc/custom.properties, unless I'm unaware of a refresh
mechanism that doesn't require restarting karaf and therefore all bundles. A
point of consideration here is that if I were to use this for endpoints, I
would have to restart the bundles producing to and consuming from them in
order to get changed property values. This is true. It still seems more
concise than bouncing the whole VM and all bundles to get the new
properties.
Here's what I know I can do as a solution:
I am able to reference a "java.util.Properties" service in one bundle when I
inject it as a property on a bean such as a class that extends RouteBuilder
in another bundle. This is perfectly viable, just not as elegant as I'd
like.
Here's what I think I should be able to do as a solution:
It appears I should be able to reference the service since it represents a
java.util.Properties object through the property placeholder thereby using
only the replacement capabilities in Camel, such as {{event.endpoint}}
whether in Blueprint DSL or in Java. Ultimately I'm trying not to have to
have some Java code to access shared properties.
I've actually tried a few permutations of the following xml snippets but
this demonstrates exactly what I'm trying to accomplish. After these
snippets I've posted some of the stack trace from karaf. I'm a little
confused why it's throwing a FileNotFoundException. I guess a subordinate
question is, does there need to be a concrete properties file somewhere or
do I possibly lack the setup of a proper Registry (see
http://camel.apache.org/using-propertyplaceholder.html under Using
Properties from the Registry section). If am missing something on the
registry maybe I need to do a little more reading on that subject.
I'm using Karaf 2.2.5.fuse-70-097 and Camel 2.9.0.fuse-70-097 in FuseESB
7.0.2.fuse-097
Here is the blueprint in the service bundle:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
xmlns:blueprint="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<service id="vmProperties" interface="java.util.Properties">
<bean class="java.util.Properties">
<argument>
<props>
<prop
key="event.endpoint">activemq:myapp.event.queue</prop>
<prop
key="command.endpoint">activemq:myapp.command.queue</prop>
</props>
</argument>
</bean>
</service>
</blueprint>
Here is the blueprint for the camel route bundle:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
xmlns:amq="http://activemq.apache.org/schema/core"
xmlns:cml="http://camel.apache.org/schema/blueprint"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0
http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint/camel-blueprint-2.9.0.xsd">
<cml:camelContext id="test-camel-context" >
<cml:propertyPlaceholder location="ref:vmProperties" />
<cml:route>
<cml:from uri="{{event.endpoint}}" />
<cml:setBody>
<cml:constant>Hello Universe</cml:constant>
</cml:setBody>
<cml:log message="########## Sending Test Message" />
<cml:to uri="{{command.endpoint}}" />
</cml:route>
<cml:route>
<cml:from uri="{{command.endpoint}}" />
<cml:log message="########## Test Message Received" />
</cml:route>
</cml:camelContext>
</blueprint>
Karaf log includes the following:
2013-02-05 10:40:12,455 | ERROR | l-0.0.0-thread-1 | BlueprintContainerImpl
| 10 - org.apache.aries.blueprint - 0.3.1.fuse-70-097 | Unable to start
blueprint container for bundle a-route.xml
org.osgi.service.blueprint.container.ComponentDefinitionException: Unable to
intialize bean test-camel-context
....
Caused by: org.apache.camel.FailedToCreateRouteException: Failed to create
route route23: Route[[From[{{event.endpoint}}]] -> [SetBody[consta...
because of Failed to resolve endpoint: {{event.endpoint}} due to: Properties
vmProperties not found in registry
...
Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to
resolve endpoint: {{event.endpoint}} due to: Properties vmProperties not
found in registry
...
Caused by: java.io.FileNotFoundException: Properties vmProperties not found
in registry
--
View this message in context: http://camel.465427.n5.nabble.com/Reference-OSGI-Blueprint-java-util-Properties-service-in-Blueprint-Camel-property-placeholder-tp5726985.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Reference OSGI Blueprint java.util.Properties service in
Blueprint Camel property placeholder
Posted by CharlieD <di...@gmail.com>.
Note, the property name doesn't match what I have in the first post. I double
checked that...mismatched strings is not the issue.
--
View this message in context: http://camel.465427.n5.nabble.com/Reference-OSGI-Blueprint-java-util-Properties-service-in-Blueprint-Camel-property-placeholder-tp5726985p5727540.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Reference OSGI Blueprint java.util.Properties service in
Blueprint Camel property placeholder
Posted by "Willem.Jiang" <wi...@gmail.com>.
Hi
I just have some time to revisit this issue and found you'd better to
leverage the configure admin service which suppose to related the bundle
when the configuration is changed. It will more powerful then you just pass
the properties through the OSGi service.
Willem
--
View this message in context: http://camel.465427.n5.nabble.com/Reference-OSGI-Blueprint-java-util-Properties-service-in-Blueprint-Camel-property-placeholder-tp5726985p5732991.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Reference OSGI Blueprint java.util.Properties service in
Blueprint Camel property placeholder
Posted by CharlieD <di...@gmail.com>.
Willem,
I did add: <reference id="vmProperties" interface="java.util.Properties"/>
However it cannot resolve the property. It is as if it can find the service
yet the properties are not there.
Caused by: java.lang.IllegalArgumentException: Property with key
[customer.event.endpoint] not found in properties from text:
{{customer.event.endpoint}}
Claus, yes I am using two separate bundles.
In my Java/Blueprint solution I put something like this:
<reference id="vmProperties" interface="java.util.Properties"/>
<bean id="myRoute" class="com.myapp.MyRoute">
<property name="props" ref="vmProperties"/>
</bean>
MyRoute extends RouteBuilder and has a class member named props.
private Properties props;
public Properties getProps() {
return props;
}
public void setProps(Properties props) {
this.props = props;
}
I then have some code logic and this solution works as I mentioned in my
first post. I can use that but wanted to see if the communal genius knew of
a better way. What solutions are out there for shared properties so that the
only related bundles need restart? I'm looking for granularity of control.
--
View this message in context: http://camel.465427.n5.nabble.com/Reference-OSGI-Blueprint-java-util-Properties-service-in-Blueprint-Camel-property-placeholder-tp5726985p5727538.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Reference OSGI Blueprint java.util.Properties service in
Blueprint Camel property placeholder
Posted by Willem jiang <wi...@gmail.com>.
Hi,
As Camel property placeholder supports to lookup the Properties from the bean reference with the prefix "ref:BeanId", I think you just need to add a reference of the property service in the camel route bundle.
--
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 Wednesday, February 6, 2013 at 2:13 AM, CharlieD wrote:
> I want to have centralized shared properties (shared across camel contexts)
> to define things, particularly ActiveMQ endpoints. Furthermore, I want to
> avoid using /etc/custom.properties, unless I'm unaware of a refresh
> mechanism that doesn't require restarting karaf and therefore all bundles. A
> point of consideration here is that if I were to use this for endpoints, I
> would have to restart the bundles producing to and consuming from them in
> order to get changed property values. This is true. It still seems more
> concise than bouncing the whole VM and all bundles to get the new
> properties.
>
> Here's what I know I can do as a solution:
> I am able to reference a "java.util.Properties" service in one bundle when I
> inject it as a property on a bean such as a class that extends RouteBuilder
> in another bundle. This is perfectly viable, just not as elegant as I'd
> like.
>
> Here's what I think I should be able to do as a solution:
> It appears I should be able to reference the service since it represents a
> java.util.Properties object through the property placeholder thereby using
> only the replacement capabilities in Camel, such as {{event.endpoint}}
> whether in Blueprint DSL or in Java. Ultimately I'm trying not to have to
> have some Java code to access shared properties.
>
> I've actually tried a few permutations of the following xml snippets but
> this demonstrates exactly what I'm trying to accomplish. After these
> snippets I've posted some of the stack trace from karaf. I'm a little
> confused why it's throwing a FileNotFoundException. I guess a subordinate
> question is, does there need to be a concrete properties file somewhere or
> do I possibly lack the setup of a proper Registry (see
> http://camel.apache.org/using-propertyplaceholder.html under Using
> Properties from the Registry section). If am missing something on the
> registry maybe I need to do a little more reading on that subject.
>
> I'm using Karaf 2.2.5.fuse-70-097 and Camel 2.9.0.fuse-70-097 in FuseESB
> 7.0.2.fuse-097
>
> Here is the blueprint in the service bundle:
>
> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
>
> xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
> xmlns:blueprint="http://www.osgi.org/xmlns/blueprint/v1.0.0">
>
> <service id="vmProperties" interface="java.util.Properties">
> <bean class="java.util.Properties">
> <argument>
> <props>
> <prop
> key="event.endpoint">activemq:myapp.event.queue</prop>
> <prop
> key="command.endpoint">activemq:myapp.command.queue</prop>
> </props>
> </argument>
> </bean>
> </service>
> </blueprint>
>
> Here is the blueprint for the camel route bundle:
>
> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
>
> xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
>
> xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
> xmlns:amq="http://activemq.apache.org/schema/core"
> xmlns:cml="http://camel.apache.org/schema/blueprint"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0
> http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
> http://camel.apache.org/schema/blueprint/camel-blueprint-2.9.0.xsd">
>
> <cml:camelContext id="test-camel-context" >
> <cml:propertyPlaceholder location="ref:vmProperties" />
> <cml:route>
> <cml:from uri="{{event.endpoint}}" />
> <cml:setBody>
> <cml:constant>Hello Universe</cml:constant>
> </cml:setBody>
> <cml:log message="########## Sending Test Message" />
> <cml:to uri="{{command.endpoint}}" />
> </cml:route>
>
> <cml:route>
> <cml:from uri="{{command.endpoint}}" />
> <cml:log message="########## Test Message Received" />
> </cml:route>
> </cml:camelContext>
> </blueprint>
>
>
> Karaf log includes the following:
>
> 2013-02-05 10:40:12,455 | ERROR | l-0.0.0-thread-1 | BlueprintContainerImpl
> | 10 - org.apache.aries.blueprint - 0.3.1.fuse-70-097 | Unable to start
> blueprint container for bundle a-route.xml
> org.osgi.service.blueprint.container.ComponentDefinitionException: Unable to
> intialize bean test-camel-context
> ....
> Caused by: org.apache.camel.FailedToCreateRouteException: Failed to create
> route route23: Route[[From[{{event.endpoint}}]] -> [SetBody[consta...
> because of Failed to resolve endpoint: {{event.endpoint}} due to: Properties
> vmProperties not found in registry
> ...
> Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to
> resolve endpoint: {{event.endpoint}} due to: Properties vmProperties not
> found in registry
> ...
> Caused by: java.io.FileNotFoundException: Properties vmProperties not found
> in registry
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Reference-OSGI-Blueprint-java-util-Properties-service-in-Blueprint-Camel-property-placeholder-tp5726985.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).
Re: Reference OSGI Blueprint java.util.Properties service in
Blueprint Camel property placeholder
Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Feb 5, 2013 at 7:13 PM, CharlieD <di...@gmail.com> wrote:
> I want to have centralized shared properties (shared across camel contexts)
> to define things, particularly ActiveMQ endpoints. Furthermore, I want to
> avoid using /etc/custom.properties, unless I'm unaware of a refresh
> mechanism that doesn't require restarting karaf and therefore all bundles. A
> point of consideration here is that if I were to use this for endpoints, I
> would have to restart the bundles producing to and consuming from them in
> order to get changed property values. This is true. It still seems more
> concise than bouncing the whole VM and all bundles to get the new
> properties.
>
> Here's what I know I can do as a solution:
> I am able to reference a "java.util.Properties" service in one bundle when I
> inject it as a property on a bean such as a class that extends RouteBuilder
> in another bundle. This is perfectly viable, just not as elegant as I'd
> like.
>
> Here's what I think I should be able to do as a solution:
> It appears I should be able to reference the service since it represents a
> java.util.Properties object through the property placeholder thereby using
> only the replacement capabilities in Camel, such as {{event.endpoint}}
> whether in Blueprint DSL or in Java. Ultimately I'm trying not to have to
> have some Java code to access shared properties.
>
> I've actually tried a few permutations of the following xml snippets but
> this demonstrates exactly what I'm trying to accomplish. After these
> snippets I've posted some of the stack trace from karaf. I'm a little
> confused why it's throwing a FileNotFoundException. I guess a subordinate
> question is, does there need to be a concrete properties file somewhere or
> do I possibly lack the setup of a proper Registry (see
> http://camel.apache.org/using-propertyplaceholder.html under Using
> Properties from the Registry section). If am missing something on the
> registry maybe I need to do a little more reading on that subject.
>
> I'm using Karaf 2.2.5.fuse-70-097 and Camel 2.9.0.fuse-70-097 in FuseESB
> 7.0.2.fuse-097
>
> Here is the blueprint in the service bundle:
>
> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
>
> xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
> xmlns:blueprint="http://www.osgi.org/xmlns/blueprint/v1.0.0">
>
> <service id="vmProperties" interface="java.util.Properties">
> <bean class="java.util.Properties">
> <argument>
> <props>
> <prop
> key="event.endpoint">activemq:myapp.event.queue</prop>
> <prop
> key="command.endpoint">activemq:myapp.command.queue</prop>
> </props>
> </argument>
> </bean>
> </service>
> </blueprint>
>
> Here is the blueprint for the camel route bundle:
>
> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
>
> xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
>
> xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
> xmlns:amq="http://activemq.apache.org/schema/core"
> xmlns:cml="http://camel.apache.org/schema/blueprint"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0
> http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
> http://camel.apache.org/schema/blueprint/camel-blueprint-2.9.0.xsd">
>
> <cml:camelContext id="test-camel-context" >
> <cml:propertyPlaceholder location="ref:vmProperties" />
> <cml:route>
> <cml:from uri="{{event.endpoint}}" />
> <cml:setBody>
> <cml:constant>Hello Universe</cml:constant>
> </cml:setBody>
> <cml:log message="########## Sending Test Message" />
> <cml:to uri="{{command.endpoint}}" />
> </cml:route>
>
> <cml:route>
> <cml:from uri="{{command.endpoint}}" />
> <cml:log message="########## Test Message Received" />
> </cml:route>
> </cml:camelContext>
> </blueprint>
>
Do you have 2 different bundles?
In the bundle with the Camel application, I would assume you need to
refer to this service in the blueprint xml file.
I can't remember the syntax for doing that, but the aries blueprint
site should have some docs on that.
>
> Karaf log includes the following:
>
> 2013-02-05 10:40:12,455 | ERROR | l-0.0.0-thread-1 | BlueprintContainerImpl
> | 10 - org.apache.aries.blueprint - 0.3.1.fuse-70-097 | Unable to start
> blueprint container for bundle a-route.xml
> org.osgi.service.blueprint.container.ComponentDefinitionException: Unable to
> intialize bean test-camel-context
> ....
> Caused by: org.apache.camel.FailedToCreateRouteException: Failed to create
> route route23: Route[[From[{{event.endpoint}}]] -> [SetBody[consta...
> because of Failed to resolve endpoint: {{event.endpoint}} due to: Properties
> vmProperties not found in registry
> ...
> Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to
> resolve endpoint: {{event.endpoint}} due to: Properties vmProperties not
> found in registry
> ...
> Caused by: java.io.FileNotFoundException: Properties vmProperties not found
> in registry
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Reference-OSGI-Blueprint-java-util-Properties-service-in-Blueprint-Camel-property-placeholder-tp5726985.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
--
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen