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/11 15:49:08 UTC
[camel] 01/02: CAMEL-14690 - Camel-AWS2: Better logging when
checking client instance in the registry, SQS
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 14024dbd81c0a1498fde743bc05dc3ad80fd0a99
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Mar 11 16:44:21 2020 +0100
CAMEL-14690 - Camel-AWS2: Better logging when checking client instance in the registry, SQS
---
.../camel/component/aws2/sqs/Sqs2Component.java | 24 +++++++++++++++++-----
1 file changed, 19 insertions(+), 5 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 c49883e..5375893 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
@@ -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.regions.Region;
import software.amazon.awssdk.services.sqs.SqsClient;
@@ -33,6 +37,8 @@ import software.amazon.awssdk.services.sqs.SqsClient;
@Component("aws2-sqs")
public class Sqs2Component extends DefaultComponent {
+ private static final Logger LOG = LoggerFactory.getLogger(Sqs2Component.class);
+
@Metadata
private Sqs2Configuration configuration = new Sqs2Configuration();
@@ -66,7 +72,7 @@ public class Sqs2Component extends DefaultComponent {
}
Sqs2Endpoint sqsEndpoint = new Sqs2Endpoint(uri, this, configuration);
setProperties(sqsEndpoint, parameters);
- checkAndSetRegistryClient(configuration);
+ checkAndSetRegistryClient(configuration, sqsEndpoint);
if (configuration.getAmazonSQSClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) {
throw new IllegalArgumentException("AmazonSQSClient or accessKey and secretKey must be specified.");
}
@@ -90,10 +96,18 @@ public class Sqs2Component extends DefaultComponent {
this.configuration = configuration;
}
- private void checkAndSetRegistryClient(Sqs2Configuration configuration) {
- Set<SqsClient> clients = getCamelContext().getRegistry().findByType(SqsClient.class);
- if (clients.size() == 1) {
- configuration.setAmazonSQSClient(clients.stream().findFirst().get());
+ 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");
}
}
}