You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2020/03/12 09:55:03 UTC

[camel] 01/02: CAMEL-14690 - Camel-AWS2: Better logging when checking client instance in the registry, MQ

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

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

commit a38319381c44e9e798c643abdcaf163ccefd8ca5
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Thu Mar 12 10:51:38 2020 +0100

    CAMEL-14690 - Camel-AWS2: Better logging when checking client instance in the registry, MQ
---
 .../camel/component/aws2/mq/MQ2Component.java      | 26 +++++++++++++++++-----
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/components/camel-aws2-mq/src/main/java/org/apache/camel/component/aws2/mq/MQ2Component.java b/components/camel-aws2-mq/src/main/java/org/apache/camel/component/aws2/mq/MQ2Component.java
index eb6619f..2b52536 100644
--- a/components/camel-aws2-mq/src/main/java/org/apache/camel/component/aws2/mq/MQ2Component.java
+++ b/components/camel-aws2-mq/src/main/java/org/apache/camel/component/aws2/mq/MQ2Component.java
@@ -24,6 +24,10 @@ import org.apache.camel.Endpoint;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.annotations.Component;
 import org.apache.camel.support.DefaultComponent;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import software.amazon.awssdk.services.mq.MqClient;
 
 /**
@@ -31,7 +35,9 @@ import software.amazon.awssdk.services.mq.MqClient;
  */
 @Component("aws2-mq")
 public class MQ2Component extends DefaultComponent {
-
+	
+    private static final Logger LOG = LoggerFactory.getLogger(MQ2Component.class);
+    
     @Metadata
     private MQ2Configuration configuration = new MQ2Configuration();
 
@@ -50,7 +56,7 @@ public class MQ2Component extends DefaultComponent {
         MQ2Configuration configuration = this.configuration != null ? this.configuration.copy() : new MQ2Configuration();
         MQ2Endpoint endpoint = new MQ2Endpoint(uri, this, configuration);
         setProperties(endpoint, parameters);
-        checkAndSetRegistryClient(configuration);
+        checkAndSetRegistryClient(configuration, endpoint);
         if (configuration.getAmazonMqClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) {
             throw new IllegalArgumentException("amazonMQClient or accessKey and secretKey must be specified");
         }
@@ -69,10 +75,18 @@ public class MQ2Component extends DefaultComponent {
         this.configuration = configuration;
     }
 
-    private void checkAndSetRegistryClient(MQ2Configuration configuration) {
-        Set<MqClient> clients = getCamelContext().getRegistry().findByType(MqClient.class);
-        if (clients.size() == 1) {
-            configuration.setAmazonMqClient(clients.stream().findFirst().get());
+    private void checkAndSetRegistryClient(MQ2Configuration configuration, MQ2Endpoint endpoint) {
+        if (ObjectHelper.isEmpty(endpoint.getConfiguration().getAmazonMqClient())) {
+            LOG.debug("Looking for an MqClient instance in the registry");
+            Set<MqClient> clients = getCamelContext().getRegistry().findByType(MqClient.class);
+            if (clients.size() == 1) {
+                LOG.debug("Found exactly one MqClient instance in the registry");
+                configuration.setAmazonMqClient(clients.stream().findFirst().get());
+            } else {
+                LOG.debug("No MqClient instance in the registry");
+            }
+        } else {
+            LOG.debug("MqClient instance is already set at endpoint level: skipping the check in the registry");
         }
     }
 }