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/11/18 07:22:14 UTC

[camel] 01/05: CAMEL-15836 - Camel-AWS2-SNS: enable autowire on the SNS Client

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 57cf6356d72aaa9f9c2cc2deceaf9bded7142b66
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Nov 18 07:57:56 2020 +0100

    CAMEL-15836 - Camel-AWS2-SNS: enable autowire on the SNS Client
---
 .../apache/camel/component/aws2/sns/Sns2Component.java | 18 ------------------
 .../camel/component/aws2/sns/Sns2Configuration.java    | 16 ++--------------
 2 files changed, 2 insertions(+), 32 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 6bf75a9..369f68bf 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
@@ -75,9 +75,6 @@ public class Sns2Component extends DefaultComponent {
             LOG.debug("Created the endpoint with topic {}", configuration.getTopicName());
         }
 
-        if (endpoint.getConfiguration().isAutoDiscoverClient()) {
-            checkAndSetRegistryClient(configuration, endpoint);
-        }
         if (configuration.getAmazonSNSClient() == null
                 && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) {
             throw new IllegalArgumentException("AmazonSNSClient or accessKey and secretKey must be specified");
@@ -135,19 +132,4 @@ public class Sns2Component extends DefaultComponent {
         this.configuration = configuration;
     }
 
-    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");
-        }
-    }
-
 }
diff --git a/components/camel-aws2-sns/src/main/java/org/apache/camel/component/aws2/sns/Sns2Configuration.java b/components/camel-aws2-sns/src/main/java/org/apache/camel/component/aws2/sns/Sns2Configuration.java
index b5994e4..3b57d19 100644
--- a/components/camel-aws2-sns/src/main/java/org/apache/camel/component/aws2/sns/Sns2Configuration.java
+++ b/components/camel-aws2-sns/src/main/java/org/apache/camel/component/aws2/sns/Sns2Configuration.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.aws2.sns;
 
 import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.UriParam;
 import org.apache.camel.spi.UriParams;
 import software.amazon.awssdk.core.Protocol;
@@ -30,6 +31,7 @@ public class Sns2Configuration implements Cloneable {
     // Common properties
     private String topicName;
     @UriParam
+    @Metadata(autowired = true)
     private SnsClient amazonSNSClient;
     @UriParam(label = "security", secret = true)
     private String accessKey;
@@ -63,8 +65,6 @@ public class Sns2Configuration implements Cloneable {
     private String region;
     @UriParam(defaultValue = "false")
     private boolean trustAllCertificates;
-    @UriParam(label = "common", defaultValue = "true")
-    private boolean autoDiscoverClient = true;
     @UriParam(defaultValue = "false")
     private boolean useIAMCredentials;
 
@@ -267,18 +267,6 @@ public class Sns2Configuration implements Cloneable {
         this.trustAllCertificates = trustAllCertificates;
     }
 
-    public boolean isAutoDiscoverClient() {
-        return autoDiscoverClient;
-    }
-
-    /**
-     * Setting the autoDiscoverClient mechanism, if true, the component will look for a client instance in the registry
-     * automatically otherwise it will skip that checking.
-     */
-    public void setAutoDiscoverClient(boolean autoDiscoverClient) {
-        this.autoDiscoverClient = autoDiscoverClient;
-    }
-
     public boolean isUseIAMCredentials() {
         return useIAMCredentials;
     }