osgi-karaf-multiple versions of service and camel route
One of the benefits of OSGi is Versioning as explained here. As per the documentation, OSGi can host different versions of "same jar" and let the other applications access them accordingly.
I have been given a task to leverage the same properties of OSGi (I am using Apache-Karaf container) using Camel routes.
I have to deploy multiple versions of a service and have Camel, route to the proper one based on the request. I extensively searched google but I haven't found a suitable example :(
Please throw me any pointers or guide me to an example.
By service, I mean osgi bundle service which is defined like this
<osgi:service ref="transformService"> <osgi:interfaces> <value>demo.service.TransformService</value> </osgi:interfaces> </osgi:service>
I have followed the steps provided in this tutorial to create a service called transformService and TransformServiceImpl is the implementation class for this service.
Now let's say I will modify TransformServiceImpl and release it as new version (by updating my version in pom.xml). Also, I will install both the versions, that is, demo.service-0.1.jar and demo.service-0.2.jar in Karaf (which is OK with Karaf). In this case how can I route to a particular version of service ?
Can I create 2 osgi:reference which points to same service but different versions? Something like this?
<osgi:reference id="myTransformV0.1" version="0.1" interface="demo.service.TransformService"/> <osgi:reference id="myTransformV0.2" version="0.2" interface="demo.service.TransformService"/>
And use them in routes?
<camelContext xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="timer://myTimer?fixedRate=true&period=10000"/> <choice> <when ...> <bean ref="myTransformV0.1" method="transform"/> <otherwise> <bean ref="myTransformV0.2" method="transform"/> </choice> <to uri="log:ExampleRouter"/> </route> </camelContext>
OSGi versioning is different from the Service versioning. I think the key question is how can you access these camel route with different version.
If your camel route provides RESTful service, it could be easy to provide different version by using different url, such as "/service/v1", "/service/v2". But it is not same with the OSGi versioning, you still need to do some work to fill the gap.