camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Willem Jiang <willem.ji...@gmail.com>
Subject Re: Proper method of looking up osgi service from camel component
Date Mon, 28 Feb 2011 07:49:45 GMT
Hi,

Here is another way to help your custom camel component not be polluted 
by OSGi APIs.
If you custom camel component has the dependency of the OSGi service, 
you just need to create a get/set method of that services interface in 
your custom component.

Then you can inject the services into the camel component by use the 
spring DM like this. and your camel component doesn't need to get touch 
with any of the OSGi API like this.

<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:osgi="http://www.springframework.org/schema/osgi"
        xsi:schemaLocation="
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/osgi 
http://www.springframework.org/schema/osgi/spring-osgi.xsd">

     <bean id="custom"
           class="com.example.CustomerCamelComponent">
         <property name="Services" ref="myServices"/>
     </bean>

     <osgi:reference id="myServices"
                     interface="com.example.osgi.Services" />

     <!-- you can add your camel route here -->

</beans>

Willem

On 2/28/11 2:58 PM, unmarshall wrote:
> Hi All,
>
> I have created a custom camel component. The endpoint for the camel
> component needs a service which is exposed by another osgi bundle. I found
> that there are couple of ways to do that:
>
> Solution 1: (Using camel API)
> -------------------
> Use CamelContextHelper.lookup("class name");
> This will internally have the following call trace:
> SpringOsgiCamelContext.getRegistry()
> PropertyPlaceholderDelegateRegistry.lookup()
> CompositeRegistry.lookup() - Here a list of registries are looked into. I
> can see 2 registries ->  OsgiRegistry&  ApplicationContextRegistry.
>
> Solution 2: (Using Spring API)
> ----------------
> Have a bean implement BundleContextAware, this will then result in injection
> of BundleContext
> which can then be used to look up a service reference and then the required
> service.
>
> As of now i have adopted solution 1 (using the camel API) as the class that
> required the service was a custom camel endpoint.
>
> Is this the right way to do it or are there better alternatives?
>
> Best Regards,
> Madhav
>


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

Mime
View raw message