You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2020/09/22 10:48:45 UTC

[camel-quarkus] 01/03: fix(mongodb): support for named clients

This is an automated email from the ASF dual-hosted git repository.

jamesnetherton pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git

commit 3fd8d6c155259132e966480b822bbda47bcab74e
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Wed Sep 2 10:36:24 2020 +0200

    fix(mongodb): support for named clients
    
    Adding the possibility to use @MongoClientName to annotate and name a mongo client and use inside the route.
    
    Closes #1608
---
 .../deployment/SupportMongoDBProcessor.java        | 23 ++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/extensions-support/mongodb/deployment/src/main/java/org/apache/camel/quarkus/support/mongodb/deployment/SupportMongoDBProcessor.java b/extensions-support/mongodb/deployment/src/main/java/org/apache/camel/quarkus/support/mongodb/deployment/SupportMongoDBProcessor.java
index ada330c..31b1b95 100644
--- a/extensions-support/mongodb/deployment/src/main/java/org/apache/camel/quarkus/support/mongodb/deployment/SupportMongoDBProcessor.java
+++ b/extensions-support/mongodb/deployment/src/main/java/org/apache/camel/quarkus/support/mongodb/deployment/SupportMongoDBProcessor.java
@@ -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())) {
-                runtimeBeans.produce(
-                        new CamelRuntimeBeanBuildItem(
-                                "camelMongoClient",
-                                "com.mongodb.client.MongoClient",
-                                mongoClient.getClient()));
-            }
+            String clientName = getMongoClientName(mongoClient.getName());
+            runtimeBeans.produce(
+                    new CamelRuntimeBeanBuildItem(
+                            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;
+    }
+
 }