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:26:56 UTC

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

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 e6d43666ed0cdd636c8c595dcea9a2ada0495381
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Thu Mar 12 10:23:31 2020 +0100

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

diff --git a/components/camel-aws2-sns/src/main/java/org/apache/camel/component/aws2/sns/Sns2Component.java b/components/camel-aws2-sns/src/main/java/org/apache/camel/component/aws2/sns/Sns2Component.java
index d13c3c5..dc774c4 100644
--- a/components/camel-aws2-sns/src/main/java/org/apache/camel/component/aws2/sns/Sns2Component.java
+++ b/components/camel-aws2-sns/src/main/java/org/apache/camel/component/aws2/sns/Sns2Component.java
@@ -24,12 +24,18 @@ 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.regions.Region;
 import software.amazon.awssdk.services.sns.SnsClient;
 
 @Component("aws2-sns")
 public class Sns2Component extends DefaultComponent {
-
+	
+    private static final Logger LOG = LoggerFactory.getLogger(Sns2Component.class);
+    
     @Metadata
     private Sns2Configuration configuration = new Sns2Configuration();
 
@@ -62,7 +68,7 @@ public class Sns2Component extends DefaultComponent {
         }
         Sns2Endpoint endpoint = new Sns2Endpoint(uri, this, configuration);
         setProperties(endpoint, parameters);
-        checkAndSetRegistryClient(configuration);
+        checkAndSetRegistryClient(configuration, endpoint);
         if (configuration.getAmazonSNSClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) {
             throw new IllegalArgumentException("AmazonSNSClient or accessKey and secretKey must be specified");
         }
@@ -81,10 +87,18 @@ public class Sns2Component extends DefaultComponent {
         this.configuration = configuration;
     }
 
-    private void checkAndSetRegistryClient(Sns2Configuration configuration) {
-        Set<SnsClient> clients = getCamelContext().getRegistry().findByType(SnsClient.class);
-        if (clients.size() == 1) {
-            configuration.setAmazonSNSClient(clients.stream().findFirst().get());
+    private void checkAndSetRegistryClient(Sns2Configuration configuration, Sns2Endpoint endpoint) {
+        if (ObjectHelper.isEmpty(endpoint.getConfiguration().getAmazonSNSClient())) {
+            LOG.debug("Looking for an SnsClient instance in the registry");
+            Set<SnsClient> clients = getCamelContext().getRegistry().findByType(SnsClient.class);
+            if (clients.size() == 1) {
+                LOG.debug("Found exactly one SnsClient instance in the registry");
+                configuration.setAmazonSNSClient(clients.stream().findFirst().get());
+            } else {
+                LOG.debug("No SnsClient instance in the registry");
+            }
+        } else {
+            LOG.debug("SnsClient instance is already set at endpoint level: skipping the check in the registry");
         }
     }
 }