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 10:05:39 UTC

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

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 83d65f1312fbc97462d8a8520f61d5ea9d89a5dc
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Thu Mar 12 11:03:04 2020 +0100

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

diff --git a/components/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/MSK2Component.java b/components/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/MSK2Component.java
index ca92a4f..8a8dbba 100644
--- a/components/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/MSK2Component.java
+++ b/components/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/MSK2Component.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.kafka.KafkaClient;
 
 /**
@@ -31,7 +35,9 @@ import software.amazon.awssdk.services.kafka.KafkaClient;
  */
 @Component("aws2-msk")
 public class MSK2Component extends DefaultComponent {
-
+	
+    private static final Logger LOG = LoggerFactory.getLogger(MSK2Component.class);
+    
     @Metadata
     private MSK2Configuration configuration = new MSK2Configuration();
 
@@ -50,7 +56,7 @@ public class MSK2Component extends DefaultComponent {
         MSK2Configuration configuration = this.configuration != null ? this.configuration.copy() : new MSK2Configuration();
         MSK2Endpoint endpoint = new MSK2Endpoint(uri, this, configuration);
         setProperties(endpoint, parameters);
-        checkAndSetRegistryClient(configuration);
+        checkAndSetRegistryClient(configuration, endpoint);
         if (configuration.getMskClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) {
             throw new IllegalArgumentException("Amazon msk client or accessKey and secretKey must be specified");
         }
@@ -68,10 +74,18 @@ public class MSK2Component extends DefaultComponent {
         this.configuration = configuration;
     }
 
-    private void checkAndSetRegistryClient(MSK2Configuration configuration) {
-        Set<KafkaClient> clients = getCamelContext().getRegistry().findByType(KafkaClient.class);
-        if (clients.size() == 1) {
-            configuration.setMskClient(clients.stream().findFirst().get());
+    private void checkAndSetRegistryClient(MSK2Configuration configuration, MSK2Endpoint endpoint) {
+        if (ObjectHelper.isEmpty(endpoint.getConfiguration().getMskClient())) {
+            LOG.debug("Looking for an KafkaClient instance in the registry");
+            Set<KafkaClient> clients = getCamelContext().getRegistry().findByType(KafkaClient.class);
+            if (clients.size() == 1) {
+                LOG.debug("Found exactly one KafkaClient instance in the registry");
+                configuration.setMskClient(clients.stream().findFirst().get());
+            } else {
+                LOG.debug("No KafkaClient instance in the registry");
+            }
+        } else {
+            LOG.debug("KafkaClient instance is already set at endpoint level: skipping the check in the registry");
         }
     }
 }