Reputation: 63
Our Camel Mongo DB component doesn't support multiple mongo db connections. By default it uses single Mongodb bean in all the mongo endpoint.
Issue:
I have created two different mongo bean instance for two database with respective authentication. And two mongodb beans instance are created in the spring.
When initializing/creating mongo endpoints(multiple endpoints with different DB) with DB its taking first mongo endpoint db connection to all the endpoint. So all the mongo endpoints are pointing to same database which was added first when creating first mongo endpoint.
Code below:
<bean id="DbLocal" name="DbLocal" class="com.mongodb.MongoClient">
<constructor-arg index="0">
<bean class="com.mongodb.MongoClientURI">
<constructor-arg index="0" value="mongodb://<user1>:<pwd1>@<host>:<port>/DB1" />
</bean>
</constructor-arg>
</bean>
<bean id="appDb" name="appDb" class="com.mongodb.MongoClient">
<constructor-arg index="0">
<bean class="com.mongodb.MongoClientURI">
<constructor-arg index="0" value="mongodb://<host>:<port>/DB2" />
</bean>
</constructor-arg>
</bean>
<route id="jobStart" startupOrder="1">
<from uri="direct:jobStart" />
<to uri="bean:jobMonitorInsertQueryBuilder" />
<to uri="mongodb:appDb?database={{requestDb}}&collection={{jobmonitorCollection}}&operation=insert"/>
</route
<route id="jobEnd" startupOrder="2">
<from uri="direct:jobEnd" />
<to uri="bean:jobMonitorUpdateQueryBuilder" />
<to uri="mongodb:DbLocal?database={{requestDb}}&collection={{jobmonitorCollection}}&operation=update" />
</route>
I tried by commenting out the if check in the camel mongo component thus allowing mongo connection look up for each mongo endpoint created in MongoDbComponent.java . This way it is working for multiple DB connections.
Any idea why mongo component is allowing only a single mongoDB connection in camel , is it because any existing issue?
protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception {
// TODO: this only supports one mongodb
//if (db == null) {
db = CamelContextHelper.mandatoryLookup(getCamelContext(), remaining, Mongo.class);
LOG.debug("Resolved the connection with the name {} as {}", remaining, db);
//}
https://github.com/apache/camel/blob/master/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbComponent.java
Appreciate any help in this regard.
Camel forum link : http://camel.465427.n5.nabble.com/Camel-mongo-db-does-not-support-multiple-mongo-DB-tp5765468.html
-Sree
Upvotes: 3
Views: 1406
Reputation: 421
This feature has been implemented in camel 2.18.2, 2.19.0. Kindly use these version to implement multiple DB's in your Project .
FYI :
https://issues.jboss.org/browse/ENTESB-5884
Jira Ticket Link - https://issues.apache.org/jira/browse/CAMEL-10644
Thanks,
Panneer
Upvotes: 0