camel-k: Unable to access MongoDB
When trying to access a MongoDB Atlas Free Tier Cluster with a Camel-K integration Java file like:
// camel-k: language=java
// camel-k: dependency=camel:mongodb
// camel-k: dependency=camel:jackson
// camel-k: dependency=mvn:org.mongodb:mongo-java-driver:3.12.10
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?hosts=[shard1].mongodb.net:27017,[shard2].mongodb.net:27017,[shard3].mongodb.net:27017&username=[user]&password=[pass]&database=[dbname]&collection=[collection-name]&operation=getDbStats")
.to("log:info");
}
}
and deploy it with Camel K Client 1.6.0 to a camel-k-operator.v1.6.0 with the command: kamel run MongoDBTest.java --dev
it results in the error:
Error processing exchange. Exchange[F6C144558CE94DA-000000000000000B]. Caused by: [org.apache.camel.component.mongodb.CamelMongoDbException - 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)}}]]: org.apache.camel.component.mongodb.CamelMongoDbException: 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)}}]
[3] at org.apache.camel.component.mongodb.MongoDbComponent.wrapInCamelMongoDbException(MongoDbComponent.java:84)
- it seems to be trying to connect to
127.0.0.1:27017
- is there something I should add to have the integration communicate with the correct hosts?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 25 (10 by maintainers)
Thanks @squakez, the quarkus.mongodb… properties is what I was missing; I was stuck at https://camel.apache.org/components/3.12.x/mongodb-component.html but never reached this document without your help: https://camel.apache.org/camel-quarkus/latest/reference/extensions/mongodb.html
The kamelets didn’t work on my end; does that mean they are also not setting those properties correctly, or did I somehow fail to deploy them correctly? - example above.
The problem is that in Camel K we support the default Camel Quarkus MongoDB client named
camelMongoClient
.This is the one we used internally in Camel K, and, in order to override its default property (which are that
127.0.0.1
you see logged), we must use a property. Your integration will work renaming the route as something like:And then, executing the Integration with:
See documentation for more details about how to configure the properties to store the values you need.