从 Camel-K 连接到 MongoDB

Connecting to MongoDB from Camel-K

如何使用 Camel-K(版本 1.6.0)连接到 MongoDB?

我试过直接在 MongoDB Camel 组件 URI 上设置主机名:

...
.to("mongodb:mongoBean?database=[redacted]&collection=[redacted]&hosts=[redacted]&username=[redacted]&password=[redacted]&operation=getDbStats")

但它坚持调用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)

可能我应该在属性文件中设置一个 class 引用,如下所示:

camel.beans.mongoBean = #class:...

但我不确定 class 应该是什么? - 还有哪些 属性 要设置的名称?

我正在部署到 Kubernetes 集群的完整 Camel-K 集成 Java 文件(OpenShift CodeReady 容器,使用命令 kamel run MongoDBTest.java --dev),如下所示:

// 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");

  }
}

在 integration.properties 文件中我有:

camel.beans.mongoBean = #class:com.mongodb.MongoClient

解决方案是设置 quarkus.mongodb... Camel Quarkus MongoDB properties, as pointed out here: https://github.com/apache/camel-k/issues/2684#issuecomment-939798018