How do I connect to MongoDB with Camel-K (version 1.6.0) ?
I've tried setting the host name directly on the MongoDB Camel component URI:
...
.to("mongodb:mongoBean?database=[redacted]&collection=[redacted]&hosts=[redacted]&username=[redacted]&password=[redacted]&operation=getDbStats")
but it insists on calling 127.0.0.1:27017:
com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=127.0.0.1:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused (Connection refused)}}]
at com.mongodb.internal.connection.BaseCluster.getDescription(BaseCluster.java:177)
Probably I should be setting a class reference in a properties file, like so:
camel.beans.mongoBean = #class:...
but then I'm not sure what class that should be? - and what other property names to set?
The full Camel-K integration Java file I'm deploying to the Kubernetes cluster (OpenShift CodeReady containers, with the command kamel run MongoDBTest.java --dev), looks like this:
// camel-k: language=java property=file:integration.properties
import org.apache.camel.builder.RouteBuilder;
public class MongoDBTest extends RouteBuilder {
@Override
public void configure() throws Exception {
from("timer:java?period=1000")
.routeId("java")
.to("mongodb:mongoBean?database=[redacted]&collection=[redacted]&operation=getDbStats&hosts=[redacted]&username=[redacted]&password=[redacted]")
.to("log:info");
}
}
and in the integration.properties file I have:
camel.beans.mongoBean = #class:com.mongodb.MongoClient
- should there be some other class reference?
- if not setting the host name on the MongoDB Camel component URI, what properties should come in there under
camel.beans.mongoBean?
The solution was to set the quarkus.mongodb... Camel Quarkus MongoDB properties, as pointed out here: https://github.com/apache/camel-k/issues/2684#issuecomment-939798018