Hi there
I am new here with a specific question about OSGi support of mongo db driver. I posted the same question on Stackobverflow (Cannot use MongoDB driver "mongodb-driver-sync" in OSGi Project: Unable to resolve - Stack Overflow) but I hope to get better support here.
The way I see it, OSGi isn’t very popular anymore, at least judging by the posts and documentation on the web. Nevertheless, Apache Karaf and OSGi is exactly the right tool for our purposes.
Our application uses Apache Camel and MongoDB.
First we successfully used a quite old version of “mongo-java-driver” (3.12.11): By adding this dependency to the modules pom.xml
and to the osgi feature repository
we were able to start our application and connect to MongoDB:
pom.xml (maven module1)
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.12.11</version>
</dependency>
feature.xml:
<repository>mvn:org.apache.camel.karaf/apache-camel/3.18.4/xml/features</repository>
<feature name="module1" description="An OSGi module" version="1.0.1-SNAPSHOT">
<feature>scr</feature>
<feature prerequisite="true">aries-blueprint</feature>
<feature>camel-core</feature>
<feature>camel-blueprint</feature>
<feature>camel-cxf</feature>
<feature>camel-xslt-saxon</feature>
<feature>camel-jetty</feature>
<feature>camel-rabbitmq</feature>
<feature>camel-openapi-java</feature>
<feature>camel-jackson</feature>
<capability>osgi.service;objectClass=org.apache.aries.blueprint.NamespaceHandler;osgi.service.blueprint.namespace=http://camel.apache.org/schema/blueprint;effective:=active;
</capability>
<bundle dependency="true">mvn:org.mongodb/mongo-java-driver/3.12.11</bundle>
<bundle>mvn:my.own.project/module1/1.0.1-SNAPSHOT</bundle>
</feature>
But that driver is legacy, quite old and missing important features, so we would like to use a modern driver, namely mongodb-driver-sync (version 4.8.2).
We replaced the previous driver with “mongodb-driver-sync”:
pom.xml (maven module1)
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
<version>4.8.2</version>
</dependency>
feature.xml:
<repository>mvn:org.apache.camel.karaf/apache-camel/3.18.4/xml/features</repository>
<feature name="module1" description="An OSGI module" version="1.0.1-SNAPSHOT">
<feature>scr</feature>
<feature prerequisite="true">aries-blueprint</feature>
<feature>camel-core</feature>
...
<!-- <bundle dependency="true">mvn:org.mongodb/mongo-java-driver/3.12.11</bundle>-->
<bundle dependency="true">mvn:org.mongodb/mongodb-driver-sync/4.8.1</bundle>
<bundle>mvn:my.own.project/module1/1.0.1-SNAPSHOT</bundle>
</feature>
This fails when starting the feature in Karaf:
Error executing command: Unable to resolve root: missing requirement [root] osgi.identity;
osgi.identity=mesh; type=karaf.feature; version="[1.0.1.SNAPSHOT,1.0.1.SNAPSHOT]";
filter:="(&(osgi.identity=mesh)(type=karaf.feature)(version>=1.0.1.SNAPSHOT)(version<=1.0.1.SNAPSHOT))"
[caused by: Unable to resolve mesh/1.0.1.SNAPSHOT: missing requirement [mesh/1.0.1.SNAPSHOT] osgi.identity; osgi.identity=mesh-vms-tso01; type=karaf.feature
[caused by: Unable to resolve mesh-vms-tso01/1.0.1.SNAPSHOT: missing requirement [mesh-vms-tso01/1.0.1.SNAPSHOT] osgi.identity; osgi.identity=mesh-vms-tso01; type=osgi.bundle; version="[1.0.1.SNAPSHOT,1.0.1.SNAPSHOT]"; resolution:=mandatory
[caused by: Unable to resolve mesh-vms-tso01/1.0.1.SNAPSHOT: missing requirement [mesh-vms-tso01/1.0.1.SNAPSHOT] osgi.wiring.package; filter:="(&(osgi.wiring.package=com.btc.mesh.core.camel)(version>=1.0.0)(!(version>=2.0.0)))"
[caused by: Unable to resolve mesh-core/1.0.1.SNAPSHOT:
missing requirement [mesh-core/1.0.1.SNAPSHOT] osgi.wiring.package; filter:="(&(osgi.wiring.package=com.mongodb)(version>=4.8.0)(!(version>=5.0.0)))"]]]]
I also tried version 4.1.0 because an older documentation mentioned that it is a valid OSGI bundle:
The mongodb-driver-sync artifact is a valid OSGi bundle whose symbolic
name is org.mongodb.driver-sync."
But we also had no luck. Does the symbolic name help in any way?
After version 4.3.x the documentation moved from mongodb.github.io
to www.mongodb.com
and the reference to OSGi has been removed. The MANIFEST file of all mentioned drivers looks quite similar including the bundle information. So, AFAIK , OSGi should work. Very confusing.
So, we need your help
- Has anyone more information about a modern MongoDB driver which is ready for OSGI?
- Or maybe we are doing something wrong when integrating the driver into our OSGI module?
Thanx