fix(mongodb): support for named clients
Adding the possibility to use to annotate and name a mongo client and use inside the route.
Closes
@@ -35,20 +35,23 @@ class SupportMongoDBProcessor {
}
@BuildStep
- void registerCamelMongoClientProducer(
+ void registerCamelMongoClientProducers(
List<MongoClientBuildItem> mongoClients,
BuildProducer<CamelRuntimeBeanBuildItem> runtimeBeans) {
for (MongoClientBuildItem mongoClient : mongoClients) {
- // If there is a default mongo client instance, then bind it to the camel registry
- // with the default mongo client name used by the camel-mongodb component
- if (MongoClientBeanUtil.isDefault(mongoClient.getName())) {
+ String clientName = getMongoClientName(mongoClient.getName());
runtimeBeans.produce(
new CamelRuntimeBeanBuildItem(
- "camelMongoClient",
+ clientName,
"com.mongodb.client.MongoClient",
mongoClient.getClient()));
}
}
+
+ private String getMongoClientName(String clientName) {
+ // Use the default mongo client instance name if it is the default connection
+ return MongoClientBeanUtil.isDefault(clientName) ? "camelMongoClient" : clientName;
}
+
}
