camel-users mailing list archives

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

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=""

     <bean id="custom"
         <property name="Services" ref="myServices"/>

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

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



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

Blog: (English)
Twitter: willemjiang

View raw message