如何使用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集群的完整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
- 是否应该有其他类引用?
- 如果没有在MongoDBCamel组件URI上设置主机名,那么在
camel.beans.mongoBean
下应该有什么属性呢?
1条答案
按热度按时间zengzsys1#
解决方法是设置quarkus.mongodb... Camel Quarkus MongoDB属性,如下所示:https://github.com/apache/camel-k/issues/2684#issuecomment-939798018