0

如何使用 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)

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

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

但是我不确定那应该是什么课程?- 以及要设置哪些其他属性名称?

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

// 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
  • 应该有其他的类参考吗?
  • 如果没有在 MongoDB Camel 组件 URI 上设置主机名,那么下面应该有哪些属性camel.beans.mongoBean
4

1 回答 1

0

解决方案是设置quarkus.mongodb ... Camel Quarkus MongoDB属性,如此处指出: https ://github.com/apache/camel-k/issues/2684#issuecomment-939798018

于 2021-10-11T18:31:36.600 回答