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 08:58:50 UTC

[camel] 01/06: CAMEL-15836 - Camel-AWS2-SQS: enable autowire on the SQS 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 9fc0316556eb8d490e0079e747d044a3d35cc2cb
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Nov 18 08:24:42 2020 +0100

    CAMEL-15836 - Camel-AWS2-SQS: enable autowire on the SQS Client
---
 .../apache/camel/component/aws2/sqs/Sqs2Component.java | 18 ------------------
 .../camel/component/aws2/sqs/Sqs2Configuration.java    | 16 ++--------------
 2 files changed, 2 insertions(+), 32 deletions(-)

diff --git a/components/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Component.java b/components/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Component.java
index 7be302b..308161c 100644
--- a/components/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Component.java
+++ b/components/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Component.java
@@ -71,9 +71,6 @@ public class Sqs2Component extends DefaultComponent {
         }
         Sqs2Endpoint sqsEndpoint = new Sqs2Endpoint(uri, this, configuration);
         setProperties(sqsEndpoint, parameters);
-        if (sqsEndpoint.getConfiguration().isAutoDiscoverClient()) {
-            checkAndSetRegistryClient(configuration, sqsEndpoint);
-        }
         if (configuration.getAmazonSQSClient() == null
                 && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) {
             throw new IllegalArgumentException("AmazonSQSClient or accessKey and secretKey must be specified.");
@@ -98,19 +95,4 @@ public class Sqs2Component extends DefaultComponent {
     public void setConfiguration(Sqs2Configuration configuration) {
         this.configuration = configuration;
     }
-
-    private void checkAndSetRegistryClient(Sqs2Configuration configuration, Sqs2Endpoint endpoint) {
-        if (ObjectHelper.isEmpty(endpoint.getConfiguration().getAmazonSQSClient())) {
-            LOG.debug("Looking for an SqsClient instance in the registry");
-            Set<SqsClient> clients = getCamelContext().getRegistry().findByType(SqsClient.class);
-            if (clients.size() == 1) {
-                LOG.debug("Found exactly one SqsClient instance in the registry");
-                configuration.setAmazonSQSClient(clients.stream().findFirst().get());
-            } else {
-                LOG.debug("No SqsClient instance in the registry");
-            }
-        } else {
-            LOG.debug("SqsClient instance is already set at endpoint level: skipping the check in the registry");
-        }
-    }
 }
diff --git a/components/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Configuration.java b/components/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Configuration.java
index 3f8b7fa..388f26b 100644
--- a/components/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Configuration.java
+++ b/components/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Configuration.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.aws2.sqs;
 
 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;
@@ -28,6 +29,7 @@ public class Sqs2Configuration implements Cloneable {
     // common properties
     private String queueName;
     @UriParam
+    @Metadata(autowired = true)
     private SqsClient amazonSQSClient;
     @UriParam(label = "security", secret = true)
     private String accessKey;
@@ -49,8 +51,6 @@ public class Sqs2Configuration implements Cloneable {
     private boolean autoCreateQueue = true;
     @UriParam(defaultValue = "false")
     private boolean trustAllCertificates;
-    @UriParam(label = "common", defaultValue = "true")
-    private boolean autoDiscoverClient = true;
 
     // consumer properties
     @UriParam(label = "consumer", defaultValue = "true")
@@ -559,18 +559,6 @@ public class Sqs2Configuration 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;
     }