This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new c93cad9  CAMEL-16526: Log and ignore connection issues in 
ConsulServiceDiscovery (#5408)
c93cad9 is described below

commit c93cad92fac1b50fc65a6f5f2c731f75726a32b9
Author: Dietrich Schulten <d...@escalon.de>
AuthorDate: Mon Apr 19 06:16:27 2021 +0200

    CAMEL-16526: Log and ignore connection issues in ConsulServiceDiscovery 
(#5408)
---
 .../consul/cloud/ConsulServiceDiscovery.java         | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git 
a/components/camel-consul/src/main/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscovery.java
 
b/components/camel-consul/src/main/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscovery.java
index da3bde4..8db6ea1 100644
--- 
a/components/camel-consul/src/main/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscovery.java
+++ 
b/components/camel-consul/src/main/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscovery.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.consul.cloud;
 
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -35,14 +36,20 @@ import org.apache.camel.impl.cloud.DefaultServiceDiscovery;
 import org.apache.camel.impl.cloud.DefaultServiceHealth;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.function.Suppliers;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public final class ConsulServiceDiscovery extends DefaultServiceDiscovery {
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(ConsulServiceDiscovery.class);
+
     private final Supplier<Consul> client;
     private final QueryOptions queryOptions;
 
     public ConsulServiceDiscovery(ConsulConfiguration configuration) throws 
Exception {
         this.client = Suppliers.memorize(() -> 
configuration.createConsulClient(getCamelContext()),
-                e -> RuntimeCamelException.wrapRuntimeCamelException(e));
+                e -> {
+                    throw RuntimeCamelException.wrapRuntimeCamelException(e);
+                });
 
         ImmutableQueryOptions.Builder builder = 
ImmutableQueryOptions.builder();
         ObjectHelper.ifNotEmpty(configuration.getDatacenter(), 
builder::datacenter);
@@ -53,10 +60,15 @@ public final class ConsulServiceDiscovery extends 
DefaultServiceDiscovery {
 
     @Override
     public List<ServiceDefinition> getServices(String name) {
-        List<CatalogService> services = 
client.get().catalogClient().getService(name, queryOptions).getResponse();
-        List<ServiceHealth> healths = 
client.get().healthClient().getAllServiceInstances(name, 
queryOptions).getResponse();
+        try {
+            List<CatalogService> services = 
client.get().catalogClient().getService(name, queryOptions).getResponse();
+            List<ServiceHealth> healths = 
client.get().healthClient().getAllServiceInstances(name, 
queryOptions).getResponse();
 
-        return services.stream().map(service -> newService(name, service, 
healths)).collect(Collectors.toList());
+            return services.stream().map(service -> newService(name, service, 
healths)).collect(Collectors.toList());
+        } catch (Exception e) {
+            LOGGER.warn("Error getting '{}' services from consul.", name, e);
+            return Collections.emptyList();
+        }
     }
 
     // *************************

Reply via email to