2.41.3. 其他 Camel Quarkus 配置
扩展利用了 Quarkus MongoDB 客户端 扩展。Mongo 客户端可以通过 Quarkus MongoDB Client 配置选项配置。
Camel Quarkus MongoDB 扩展自动注册一个名为 camelMongoClient
的 MongoDB 客户端。这可以在 mongodb endpoint URI connectionBean
路径参数中引用。例如:
from("direct:start") .to("mongodb:camelMongoClient?database=myDb&collection=myCollection&operation=findAll")
如果您的应用程序需要使用多个 MongoDB 服务器,您可以通过注入客户端和相关配置,在路由中创建"命名"客户端并引用,如 Quarkus MongoDB 扩展客户端注入 中所述。例如:
//application.properties quarkus.mongodb.mongoClient1.connection-string = mongodb://root:example@localhost:27017/
//Routes.java @ApplicationScoped public class Routes extends RouteBuilder { @Inject @MongoClientName("mongoClient1") MongoClient mongoClient1; @Override public void configure() throws Exception { from("direct:defaultServer") .to("mongodb:camelMongoClient?database=myDb&collection=myCollection&operation=findAll") from("direct:otherServer") .to("mongodb:mongoClient1?database=myOtherDb&collection=myOtherCollection&operation=findAll"); } }
请注意,在使用指定客户端时,仍会生成 "default" camelMongoClient
bean。如需更多信息,请参阅有关 多个 MongoDB 客户端的 Quarkus 文档。