-
1. Re: OSGi Pure Service and Camel Route.
njiang Jun 30, 2009 11:28 PM (in response to pchandler)Camel will lookup the jndi registry to find the instance of the bean object with the name. If you can put your OSGi service to this registry , then camel can find it without any trouble.
Spring DM makes the Spring beans export as the OSGi service out of box. I don't know if you could import the OSGi service in the spring context, if so , you can define the bean endpoint name with the import OSGi service name , and you can use it in the camel context as the bean's endpoint name.
If not, we need to do some enhancement to let camel osgi module can look up the OSGi service from the bundle context.
-
2. Re: OSGi Pure Service and Camel Route.
pchandler Jul 1, 2009 10:08 AM (in response to njiang)I guess I am still a bit confused.
My OSGi Service registers itself (in the start method of the Activator) in the OSGi registry:
// register the service
serviceReg = context.registerService(
MyService.class.getName(),
new MyServiceImpl("com.mycompany.package"),
null);
So, Camel does not use the OSGi registry but a separate/different jndi registry?
For Camel to use a OSGi Service you must start the service via a bean XML configuration files?
I must create a my-service-bundle-context.xml and a bundle-context-osgi.xml
in META-INF/spring ?
To use Camel you can't have you own OSGi Activators?
Camel only find Spring enable OSGi bundles?
Sorry for all the question,
Peter.
-
3. Re: OSGi Pure Service and Camel Route.
pchandler Jul 1, 2009 5:38 PM (in response to njiang)So, there is no way to bind (create an Endpoint) to an OSGi registered service?
http://camel.apache.org/uris.html
Would be nice to have an OSGi URi.
Peter,
-
4. Re: OSGi Pure Service and Camel Route.
davsclaus Jul 2, 2009 12:35 AM (in response to pchandler)Hi Peter
Feel free to add a ticket for this in JIRA either at fusesource or at apache.
There is a org.apache.camel.spi.Registry allowing to use a pluggable registry instead of the default that will be spring application context based.
Having Camel to be able to lookup in both would be nice.
-
-
6. Re: OSGi Pure Service and Camel Route.
njiang Jul 9, 2009 5:51 AM (in response to njiang)I just did a quick fix for the CAMEL-1789 today, please feel free to try it out.
-
7. Re: OSGi Pure Service and Camel Route.
njiang Jul 9, 2009 10:29 PM (in response to pchandler)Hi Peter,
Spring DM support the reference of OSGi service, if you don't have chance to try my latest fix, you could try to add the below lines into your spring configuration file.
<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"
<osgi:reference id="someService" interface="com.xyz.AService"/>
...
</beans>
Then you can use the beans URI to reference this someService.
Willem
-
8. Re: OSGi Pure Service and Camel Route.
pchandler Jul 22, 2009 6:50 PM (in response to njiang)Thanks,
Do you have an example (CamelContext.xml) of how one invokes an "pure"(non-spring) OSGi service from camel after the fix?
Any chance of getting a osgi URI for camel?
<ca:to uri="osgi:MyRegisteredOSGiService?method=methodName"/>
-
9. Re: OSGi Pure Service and Camel Route.
pchandler Jul 24, 2009 3:39 PM (in response to njiang)Usage example please?
Will the below code return the OSGi BundleContext?
CamelContextFactoryBean beanFactory = new CamelContextFactoryBean();
BundleContext context = beanFactory.getBundleContext();
Thanks,
Peter.
-
10. Re: OSGi Pure Service and Camel Route.
oisin Jul 24, 2009 4:55 PM (in response to pchandler)Hi Peter
After the fix, you should be able to use the bean: URI to get access to the OSGi service. In the Spring world, Camel checks the Spring Application Context to get the bean by name. What the fix does is add the the OSGi Service Registry before the Spring Application Context for the resolution of bean: components.
So if you have a service org.example.MyService, the syntax
<to uri="bean:org.example.MyService?method=methodName"/>
should resolve and invoke the service you have registered.
I have to admit, however, I haven't tried this out yet, but that is how the unit
test is designed to work.
--oh
-
11. Re: OSGi Pure Service and Camel Route.
njiang Jul 24, 2009 9:17 PM (in response to pchandler)Hi ,
You can use it as the bean endpoint like this
<ca:to uri="bean:TheOSGiServiceInterfaceName?method=methodName"/>
-
12. Re: OSGi Pure Service and Camel Route.
njiang Jul 24, 2009 9:22 PM (in response to pchandler)Since Spring DM will Inject the bundle context for your, if you use Spring to create that CamelContextFactoryBean, you will get the bundle context, Otherwise you can't get the bundle context.
-
13. Re: OSGi Pure Service and Camel Route.
pchandler Jul 27, 2009 3:29 PM (in response to njiang)META-INF/spring/CamelContext.xml:
...
Constructor for MyImpl:
public MyImpl() {
CamelContextFactoryBean beanFactory = new CamelContextFactoryBean();
BundleContext context = beanFactory.getBundleContext();
if (context == null)
{
log.info("***Bundle Context is null" );
return;
}
Output:
***Bundle Context is null
Can not get a reference to the bundle context from the spring bean? Bug? or not?
-
14. Re: OSGi Pure Service and Camel Route.
davsclaus Jul 28, 2009 2:53 AM (in response to pchandler)Yes you cannot do as you do by creating a new CamelContextFactoryBean and then expect it is initialized with OSGi. You should not really construct this factory bean yourself.
Its a spring factory bean and thus part of spring doing its initialization.
I would assume there are more standard ways of getting a bundle context in OSGi land. Eg try look outside Camel and look how to get the bundle context in pure OSGi.
You can get hold of the camel context though in your bean. Just get the camelContext tag an id, eg
And then I assume you can use it to get the bundle context.