datacenters = new HashMap<>();
-
- /**
- * Tag to query for in service list if one is not listed in serverListQueryTags.
- * Multiple tags can be specified with a comma separated value.
- */
- private String defaultQueryTag;
-
- /**
- * Add the 'passing` parameter to /v1/health/service/serviceName. This pushes health
- * check passing to the server.
- */
- private boolean queryPassing = false;
-
- /** Register as a service in consul. */
- private boolean register = true;
-
- /** Disable automatic de-registration of service in consul. */
- private boolean deregister = true;
-
- /** Register health check in consul. Useful during development of a service. */
- private boolean registerHealthCheck = true;
-
- /**
- * Throw exceptions during service registration if true, otherwise, log warnings
- * (defaults to true).
- */
- private boolean failFast = true;
-
- /**
- * Skips certificate verification during service checks if true, otherwise runs
- * certificate verification.
- */
- private Boolean healthCheckTlsSkipVerify;
-
- /**
- * Order of the discovery client used by `CompositeDiscoveryClient` for sorting
- * available clients.
- */
- private int order = 0;
-
- @SuppressWarnings("unused")
- private ConsulDiscoveryProperties() {
- this(new InetUtils(new InetUtilsProperties()));
- }
-
- public ConsulDiscoveryProperties(InetUtils inetUtils) {
- this.managementTags.add(MANAGEMENT);
- this.hostInfo = inetUtils.findFirstNonLoopbackHostInfo();
- this.ipAddress = this.hostInfo.getIpAddress();
- this.hostname = this.hostInfo.getHostname();
- }
-
- /**
- * Gets the tag to use when looking up the instances for a particular service. If the
- * service has an entry in {@link #serverListQueryTags} that will be used. Otherwise
- * the content of {@link #defaultQueryTag} will be used.
- * @param serviceId the service whose instances are being looked up
- * @return the tag to filter the service instances by or null if no tags are
- * configured for the service and the default query tag is not configured
- */
- public String getQueryTagForService(String serviceId) {
- String tag = this.serverListQueryTags.get(serviceId);
- return tag != null ? tag : this.defaultQueryTag;
- }
-
- /**
- * Gets the array of tags to use when looking up the instances for a particular
- * service. If the service has an entry in {@link #serverListQueryTags} that will be
- * used. Otherwise the content of {@link #defaultQueryTag} will be used. This differs
- * from {@link #getQueryTagForService(String)} in that it assumes the configured tag
- * property value may represent multiple tags when separated by commas. When the tag
- * property is set to a single tag then this method behaves identical to its
- * aforementioned counterpart except that it returns a single element array with the
- * single tag value.
- *
- * The expected format of the tag property value is {@code tag1,tag2,..,tagN}.
- * Whitespace will be trimmed off each entry.
- * @param serviceId the service whose instances are being looked up
- * @return the array of tags to filter the service instances by - it will be null if
- * no tags are configured for the service and the default query tag is not configured
- * or if a single tag is configured and it is the empty string
- */
- @Nullable
- public String[] getQueryTagsForService(String serviceId) {
- String queryTagStr = getQueryTagForService(serviceId);
- if (queryTagStr == null || queryTagStr.isEmpty()) {
- return null;
- }
- return StringUtils.tokenizeToStringArray(queryTagStr, ",");
- }
-
- public String getHostname() {
- return this.preferIpAddress ? this.ipAddress : this.hostname;
- }
-
- public void setHostname(String hostname) {
- this.hostname = hostname;
- this.hostInfo.override = true;
- }
-
- private HostInfo getHostInfo() {
- return this.hostInfo;
- }
-
- private void setHostInfo(HostInfo hostInfo) {
- this.hostInfo = hostInfo;
- }
-
- public String getAclToken() {
- return this.aclToken;
- }
-
- public void setAclToken(String aclToken) {
- this.aclToken = aclToken;
- }
-
- public List getTags() {
- return this.tags;
- }
-
- public void setTags(List tags) {
- this.tags = tags;
- }
-
- public boolean isEnableTagOverride() {
- return enableTagOverride;
- }
-
- public void setEnableTagOverride(boolean enableTagOverride) {
- this.enableTagOverride = enableTagOverride;
- }
-
- public Map getMetadata() {
- return metadata;
- }
-
- public void setMetadata(Map metadata) {
- this.metadata = metadata;
- }
-
- public boolean isEnabled() {
- return this.enabled;
- }
-
- public void setEnabled(boolean enabled) {
- this.enabled = enabled;
- }
-
- public List getManagementTags() {
- return this.managementTags;
- }
-
- public void setManagementTags(List managementTags) {
- this.managementTags = managementTags;
- }
-
- public String getHealthCheckPath() {
- return this.healthCheckPath;
- }
-
- public void setHealthCheckPath(String healthCheckPath) {
- this.healthCheckPath = healthCheckPath;
- }
-
- public String getHealthCheckUrl() {
- return this.healthCheckUrl;
- }
-
- public void setHealthCheckUrl(String healthCheckUrl) {
- this.healthCheckUrl = healthCheckUrl;
- }
-
- public Map> getHealthCheckHeaders() {
- return this.healthCheckHeaders;
- }
-
- public void setHealthCheckHeaders(Map> healthCheckHeaders) {
- this.healthCheckHeaders = healthCheckHeaders;
- }
-
- public String getHealthCheckInterval() {
- return this.healthCheckInterval;
- }
-
- public void setHealthCheckInterval(String healthCheckInterval) {
- this.healthCheckInterval = healthCheckInterval;
- }
-
- public String getHealthCheckTimeout() {
- return this.healthCheckTimeout;
- }
-
- public void setHealthCheckTimeout(String healthCheckTimeout) {
- this.healthCheckTimeout = healthCheckTimeout;
- }
-
- public String getHealthCheckCriticalTimeout() {
- return this.healthCheckCriticalTimeout;
- }
-
- public void setHealthCheckCriticalTimeout(String healthCheckCriticalTimeout) {
- this.healthCheckCriticalTimeout = healthCheckCriticalTimeout;
- }
-
- public String getIpAddress() {
- return this.ipAddress;
- }
-
- public void setIpAddress(String ipAddress) {
- this.ipAddress = ipAddress;
- this.hostInfo.override = true;
- }
-
- public Integer getPort() {
- return this.port;
- }
-
- public void setPort(Integer port) {
- this.port = port;
- }
-
- public Integer getManagementPort() {
- return this.managementPort;
- }
-
- public void setManagementPort(Integer managementPort) {
- this.managementPort = managementPort;
- }
-
- public Lifecycle getLifecycle() {
- return this.lifecycle;
- }
-
- public void setLifecycle(Lifecycle lifecycle) {
- this.lifecycle = lifecycle;
- }
-
- public boolean isPreferIpAddress() {
- return this.preferIpAddress;
- }
-
- public void setPreferIpAddress(boolean preferIpAddress) {
- this.preferIpAddress = preferIpAddress;
- }
-
- public boolean isPreferAgentAddress() {
- return this.preferAgentAddress;
- }
-
- public void setPreferAgentAddress(boolean preferAgentAddress) {
- this.preferAgentAddress = preferAgentAddress;
- }
-
- public int getCatalogServicesWatchDelay() {
- return this.catalogServicesWatchDelay;
- }
-
- public void setCatalogServicesWatchDelay(int catalogServicesWatchDelay) {
- this.catalogServicesWatchDelay = catalogServicesWatchDelay;
- }
-
- public int getCatalogServicesWatchTimeout() {
- return this.catalogServicesWatchTimeout;
- }
-
- public void setCatalogServicesWatchTimeout(int catalogServicesWatchTimeout) {
- this.catalogServicesWatchTimeout = catalogServicesWatchTimeout;
- }
-
- public String getServiceName() {
- return this.serviceName;
- }
-
- public void setServiceName(String serviceName) {
- this.serviceName = serviceName;
- }
-
- public String getInstanceId() {
- return this.instanceId;
- }
-
- public void setInstanceId(String instanceId) {
- this.instanceId = instanceId;
- }
-
- public String getInstanceZone() {
- return this.instanceZone;
- }
-
- public void setInstanceZone(String instanceZone) {
- this.instanceZone = instanceZone;
- }
-
- public String getInstanceGroup() {
- return this.instanceGroup;
- }
-
- public void setInstanceGroup(String instanceGroup) {
- this.instanceGroup = instanceGroup;
- }
-
- public boolean isIncludeHostnameInInstanceId() {
- return includeHostnameInInstanceId;
- }
-
- public void setIncludeHostnameInInstanceId(boolean includeHostnameInInstanceId) {
- this.includeHostnameInInstanceId = includeHostnameInInstanceId;
- }
-
- public ConsistencyMode getConsistencyMode() {
- return consistencyMode;
- }
-
- public void setConsistencyMode(ConsistencyMode consistencyMode) {
- this.consistencyMode = consistencyMode;
- }
-
- public String getDefaultZoneMetadataName() {
- return this.defaultZoneMetadataName;
- }
-
- public void setDefaultZoneMetadataName(String defaultZoneMetadataName) {
- this.defaultZoneMetadataName = defaultZoneMetadataName;
- }
-
- public String getScheme() {
- return this.scheme;
- }
-
- public void setScheme(String scheme) {
- this.scheme = scheme;
- }
-
- public String getManagementSuffix() {
- return this.managementSuffix;
- }
-
- public void setManagementSuffix(String managementSuffix) {
- this.managementSuffix = managementSuffix;
- }
-
- public Map getServerListQueryTags() {
- return this.serverListQueryTags;
- }
-
- public void setServerListQueryTags(Map serverListQueryTags) {
- this.serverListQueryTags = serverListQueryTags;
- }
-
- public Map getDatacenters() {
- return this.datacenters;
- }
-
- public void setDatacenters(Map datacenters) {
- this.datacenters = datacenters;
- }
-
- public String getDefaultQueryTag() {
- return this.defaultQueryTag;
- }
-
- public void setDefaultQueryTag(String defaultQueryTag) {
- this.defaultQueryTag = defaultQueryTag;
- }
-
- public boolean isQueryPassing() {
- return this.queryPassing;
- }
-
- public void setQueryPassing(boolean queryPassing) {
- this.queryPassing = queryPassing;
- }
-
- public boolean isRegister() {
- return this.register;
- }
-
- public void setRegister(boolean register) {
- this.register = register;
- }
-
- public boolean isDeregister() {
- return this.deregister;
- }
-
- public void setDeregister(boolean deregister) {
- this.deregister = deregister;
- }
-
- public boolean isRegisterHealthCheck() {
- return this.registerHealthCheck;
- }
-
- public void setRegisterHealthCheck(boolean registerHealthCheck) {
- this.registerHealthCheck = registerHealthCheck;
- }
-
- public boolean isFailFast() {
- return this.failFast;
- }
-
- public void setFailFast(boolean failFast) {
- this.failFast = failFast;
- }
-
- public Boolean getHealthCheckTlsSkipVerify() {
- return this.healthCheckTlsSkipVerify;
- }
-
- public void setHealthCheckTlsSkipVerify(Boolean healthCheckTlsSkipVerify) {
- this.healthCheckTlsSkipVerify = healthCheckTlsSkipVerify;
- }
-
- public int getOrder() {
- return this.order;
- }
-
- public void setOrder(int order) {
- this.order = order;
- }
-
- public Map getManagementMetadata() {
- return this.managementMetadata;
- }
-
- public void setManagementMetadata(Map managementMetadata) {
- this.managementMetadata = managementMetadata;
- }
-
- public Boolean getEnableTagOverride() {
- return this.enableTagOverride;
- }
-
- public void setEnableTagOverride(Boolean enableTagOverride) {
- this.enableTagOverride = enableTagOverride;
- }
-
- public Boolean getManagementEnableTagOverride() {
- return this.managementEnableTagOverride;
- }
-
- public void setManagementEnableTagOverride(Boolean managementEnableTagOverride) {
- this.managementEnableTagOverride = managementEnableTagOverride;
- }
-
- @Override
- public String toString() {
- return new ToStringCreator(this).append("aclToken", this.aclToken)
- .append("catalogServicesWatchDelay", this.catalogServicesWatchDelay)
- .append("catalogServicesWatchTimeout", this.catalogServicesWatchTimeout)
- .append("consistencyMode", this.consistencyMode).append("datacenters", this.datacenters)
- .append("defaultQueryTag", this.defaultQueryTag)
- .append("defaultZoneMetadataName", this.defaultZoneMetadataName).append("deregister", this.deregister)
- .append("enabled", this.enabled).append("enableTagOverride", this.enableTagOverride)
- .append("failFast", this.failFast).append("hostInfo", this.hostInfo)
- .append("healthCheckCriticalTimeout", this.healthCheckCriticalTimeout)
- .append("healthCheckHeaders", this.healthCheckHeaders)
- .append("healthCheckInterval", this.healthCheckInterval).append("healthCheckPath", this.healthCheckPath)
- .append("healthCheckTimeout", this.healthCheckTimeout)
- .append("healthCheckTlsSkipVerify", this.healthCheckTlsSkipVerify)
- .append("healthCheckUrl", this.healthCheckUrl).append("hostname", this.hostname)
- .append("includeHostnameInInstanceId", this.includeHostnameInInstanceId)
- .append("instanceId", this.instanceId).append("instanceGroup", this.instanceGroup)
- .append("instanceZone", this.instanceZone).append("ipAddress", this.ipAddress)
- .append("lifecycle", this.lifecycle).append("metadata", this.metadata)
- .append("managementEnableTagOverride", this.managementEnableTagOverride)
- .append("managementMetadata", this.managementMetadata).append("managementPort", this.managementPort)
- .append("managementSuffix", this.managementSuffix).append("managementTags", this.managementTags)
- .append("order", this.order).append("port", this.port)
- .append("preferAgentAddress", this.preferAgentAddress).append("preferIpAddress", this.preferIpAddress)
- .append("queryPassing", this.queryPassing).append("register", this.register)
- .append("registerHealthCheck", this.registerHealthCheck).append("scheme", this.scheme)
- .append("serviceName", this.serviceName).append("serverListQueryTags", this.serverListQueryTags)
- .append("tags", this.tags).toString();
- }
-
- /**
- * Properties releated to the lifecycle.
- */
- public static class Lifecycle {
-
- private boolean enabled = true;
-
- public boolean isEnabled() {
- return this.enabled;
- }
-
- public void setEnabled(boolean enabled) {
- this.enabled = enabled;
- }
-
- @Override
- public String toString() {
- return "Lifecycle{" + "enabled=" + this.enabled + '}';
- }
-
- }
-
-}
diff --git a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulServerUtils.java b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulServerUtils.java
deleted file mode 100644
index a9ed9cb5..00000000
--- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulServerUtils.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.consul.discovery;
-
-import java.net.Inet6Address;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-
-import com.ecwid.consul.v1.health.model.HealthService;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import org.springframework.util.StringUtils;
-
-/**
- * @author Spencer Gibb
- * @author Semenkov Alexey
- */
-public final class ConsulServerUtils {
-
- private static final Log log = LogFactory.getLog(ConsulServerUtils.class);
-
- private ConsulServerUtils() {
- throw new IllegalStateException("Can't instantiate a utility class");
- }
-
- public static String findHost(HealthService healthService) {
- HealthService.Service service = healthService.getService();
- HealthService.Node node = healthService.getNode();
-
- if (StringUtils.hasText(service.getAddress())) {
- return fixIPv6Address(service.getAddress());
- }
- else if (StringUtils.hasText(node.getAddress())) {
- return fixIPv6Address(node.getAddress());
- }
- return node.getNode();
- }
-
- public static String fixIPv6Address(String address) {
- try {
- InetAddress inetAdr = InetAddress.getByName(address);
- if (inetAdr instanceof Inet6Address) {
- return "[" + inetAdr.getHostAddress() + "]";
- }
- return address;
- }
- catch (UnknownHostException e) {
- log.debug("Not InetAddress: " + address + " , resolved as is.");
- return address;
- }
- }
-
-}
diff --git a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulServiceInstance.java b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulServiceInstance.java
deleted file mode 100644
index 94dbddd5..00000000
--- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulServiceInstance.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright 2015-2020 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.consul.discovery;
-
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-import com.ecwid.consul.v1.health.model.HealthService;
-
-import org.springframework.cloud.client.DefaultServiceInstance;
-import org.springframework.core.style.ToStringCreator;
-
-import static org.springframework.cloud.consul.discovery.ConsulServerUtils.findHost;
-
-public class ConsulServiceInstance extends DefaultServiceInstance {
-
- private HealthService healthService;
-
- public ConsulServiceInstance(HealthService healthService, String serviceId) {
- this(healthService.getService().getId(), serviceId, findHost(healthService),
- getPort(healthService.getService()), getSecure(healthService), getMetadata(healthService),
- healthService.getService().getTags());
- this.healthService = healthService;
- }
-
- public ConsulServiceInstance(String instanceId, String serviceId, String host, int port, boolean secure,
- Map metadata, List tags) {
- super(instanceId, serviceId, host, port, secure, metadata);
- }
-
- public ConsulServiceInstance(String instanceId, String serviceId, String host, int port, boolean secure) {
- super(instanceId, serviceId, host, port, secure);
- }
-
- public ConsulServiceInstance() {
- }
-
- private static Map getMetadata(HealthService healthService) {
- Map metadata = healthService.getService().getMeta();
- if (metadata == null) {
- metadata = new LinkedHashMap<>();
- }
- return metadata;
- }
-
- private static int getPort(HealthService.Service service) {
- Integer port = service.getPort();
- // Services without registered port receive '0' from consul 1.9 and null from
- // consul 1.10
- if (port == null) {
- return 0;
- }
- return port;
- }
-
- private static boolean getSecure(HealthService healthService) {
- boolean secure = false;
- Map metadata = getMetadata(healthService);
- // getMetadata() above returns an empty Map if meta is null
- if (metadata.containsKey("secure")) {
- secure = Boolean.parseBoolean(metadata.get("secure"));
- }
- return secure;
- }
-
- public HealthService getHealthService() {
- return this.healthService;
- }
-
- public void setHealthService(HealthService healthService) {
- this.healthService = healthService;
- }
-
- public List getTags() {
- if (healthService != null) {
- return healthService.getService().getTags();
- }
- return Collections.emptyList();
- }
-
- @Override
- public String toString() {
- return new ToStringCreator(this).append("instanceId", getInstanceId()).append("serviceId", getServiceId())
- .append("host", getHost()).append("port", getPort()).append("secure", isSecure())
- .append("metadata", getMetadata()).append("uri", getUri()).append("healthService", healthService)
- .toString();
-
- }
-
-}
diff --git a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/HeartbeatProperties.java b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/HeartbeatProperties.java
deleted file mode 100644
index c501e56b..00000000
--- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/HeartbeatProperties.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.consul.discovery;
-
-import java.time.Duration;
-import java.time.temporal.ChronoUnit;
-
-import jakarta.validation.constraints.DecimalMax;
-import jakarta.validation.constraints.DecimalMin;
-import org.apache.commons.logging.Log;
-
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.boot.convert.DurationUnit;
-import org.springframework.core.style.ToStringCreator;
-import org.springframework.validation.annotation.Validated;
-
-/**
- * Properties related to heartbeat verification.
- *
- * @author Spencer Gibb
- * @author Chris Bono
- */
-@ConfigurationProperties(prefix = "spring.cloud.consul.discovery.heartbeat")
-@Validated
-public class HeartbeatProperties {
-
- private static final Log log = org.apache.commons.logging.LogFactory.getLog(HeartbeatProperties.class);
-
- // TODO: change enabled to default to true when I stop seeing messages like
- // [WARN] agent: Check 'service:testConsulApp:xtest:8080' missed TTL, is now critical
- boolean enabled = false;
-
- @DurationUnit(ChronoUnit.SECONDS)
- private Duration ttl = Duration.ofSeconds(30);
-
- @DecimalMin("0.1")
- @DecimalMax("0.9")
- private double intervalRatio = 2.0 / 3.0;
-
- private boolean reregisterServiceOnFailure = false;
-
- /**
- * Whether or not to take the current system health (as reported via the Actuator
- * Health endpoint) into account when reporting the application status to the Consul
- * TTL check. Actuator Health endpoint also has to be available to the application.
- */
- private boolean useActuatorHealth = true;
-
- /**
- * The actuator health group to use (null for the root group) when determining system
- * health via Actuator.
- */
- private String actuatorHealthGroup;
-
- /**
- * @return the computed heartbeat interval
- */
- protected Duration computeHeartbeatInterval() {
- // heartbeat rate at ratio * ttl, but no later than ttl -1s and, (under lesser
- // priority), no sooner than 1s from now
- double interval = this.ttl.getSeconds() * this.intervalRatio;
- double max = Math.max(interval, 1);
- long ttlMinus1 = this.ttl.getSeconds() - 1;
- double min = Math.min(ttlMinus1, max);
- Duration heartbeatInterval = Duration.ofMillis(Math.round(1000 * min));
- log.debug("Computed heartbeatInterval: " + heartbeatInterval);
- return heartbeatInterval;
- }
-
- public boolean isEnabled() {
- return this.enabled;
- }
-
- public void setEnabled(boolean enabled) {
- this.enabled = enabled;
- }
-
- public Duration getTtl() {
- return this.ttl;
- }
-
- public void setTtl(Duration ttl) {
- this.ttl = ttl;
- }
-
- public @DecimalMin("0.1") @DecimalMax("0.9") double getIntervalRatio() {
- return this.intervalRatio;
- }
-
- public void setIntervalRatio(@DecimalMin("0.1") @DecimalMax("0.9") double intervalRatio) {
- this.intervalRatio = intervalRatio;
- }
-
- public boolean isReregisterServiceOnFailure() {
- return this.reregisterServiceOnFailure;
- }
-
- public void setReregisterServiceOnFailure(boolean reregisterServiceOnFailure) {
- this.reregisterServiceOnFailure = reregisterServiceOnFailure;
- }
-
- public boolean isUseActuatorHealth() {
- return useActuatorHealth;
- }
-
- public void setUseActuatorHealth(boolean useActuatorHealth) {
- this.useActuatorHealth = useActuatorHealth;
- }
-
- public String getActuatorHealthGroup() {
- return actuatorHealthGroup;
- }
-
- public void setActuatorHealthGroup(String actuatorHealthGroup) {
- this.actuatorHealthGroup = actuatorHealthGroup;
- }
-
- @Override
- public String toString() {
- return new ToStringCreator(this).append("enabled", this.enabled).append("ttl", this.ttl)
- .append("intervalRatio", this.intervalRatio).append("useActuatorHealth", this.useActuatorHealth)
- .append("healthGroup", this.actuatorHealthGroup).toString();
- }
-
-}
diff --git a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ReregistrationPredicate.java b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ReregistrationPredicate.java
deleted file mode 100644
index 2a9d8088..00000000
--- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ReregistrationPredicate.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.consul.discovery;
-
-import com.ecwid.consul.v1.OperationException;
-
-/**
- * Predicate on whether to re-register service.
- *
- * @author Toshiaki Maki
- */
-public interface ReregistrationPredicate {
-
- /**
- * test if the exception is eligible for re-registration.
- * @param e OperationException
- * @return if the exception is eligible for re-registration
- */
- boolean isEligible(OperationException e);
-
- /**
- * Default implementation that performs re-registration when the status code is either
- * 404 or 500.
- */
- ReregistrationPredicate DEFAULT = e -> (e.getStatusCode() == 404 || e.getStatusCode() == 500);
-
-}
diff --git a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/TtlScheduler.java b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/TtlScheduler.java
deleted file mode 100644
index 5c052024..00000000
--- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/TtlScheduler.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.consul.discovery;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledFuture;
-import java.util.function.Supplier;
-
-import com.ecwid.consul.v1.ConsulClient;
-import com.ecwid.consul.v1.OperationException;
-import com.ecwid.consul.v1.agent.model.NewService;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import org.springframework.beans.factory.ObjectProvider;
-import org.springframework.cloud.consul.serviceregistry.ApplicationStatusProvider;
-import org.springframework.scheduling.TaskScheduler;
-import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler;
-
-import static com.ecwid.consul.v1.health.model.Check.CheckStatus;
-
-/**
- * Created by nicu on 11.03.2015.
- *
- * @author Stéphane LEROY
- * @author Chris Bono
- */
-public class TtlScheduler {
-
- private static final Log log = LogFactory.getLog(TtlScheduler.class);
-
- private final Map serviceHeartbeats = new ConcurrentHashMap<>();
-
- private final TaskScheduler scheduler = new ConcurrentTaskScheduler(Executors.newSingleThreadScheduledExecutor());
-
- private final HeartbeatProperties heartbeatProperties;
-
- private final ConsulDiscoveryProperties discoveryProperties;
-
- private final ConsulClient client;
-
- private final ReregistrationPredicate reregistrationPredicate;
-
- private final Map registeredServices = new ConcurrentHashMap<>();
-
- private ApplicationStatusProvider applicationStatusProvider;
-
- public TtlScheduler(HeartbeatProperties heartbeatProperties, ConsulDiscoveryProperties discoveryProperties,
- ConsulClient client, ReregistrationPredicate reregistrationPredicate,
- ObjectProvider applicationStatusProviderFactory) {
- this.heartbeatProperties = heartbeatProperties;
- this.discoveryProperties = discoveryProperties;
- this.client = client;
- this.reregistrationPredicate = reregistrationPredicate;
- this.applicationStatusProvider = applicationStatusProviderFactory
- .getIfAvailable(() -> () -> CheckStatus.PASSING);
- }
-
- public void add(final NewService service) {
- add(service.getId());
- this.registeredServices.put(service.getId(), service);
- }
-
- /**
- * Add a service to the checks loop.
- * @param instanceId instance id
- */
- public void add(String instanceId) {
- ScheduledFuture task = this.scheduler.scheduleAtFixedRate(
- new ConsulHeartbeatTask(instanceId, this, () -> applicationStatusProvider.currentStatus()),
- this.heartbeatProperties.computeHeartbeatInterval().toMillis());
- ScheduledFuture previousTask = this.serviceHeartbeats.put(instanceId, task);
- if (previousTask != null) {
- previousTask.cancel(true);
- }
- }
-
- public void remove(String instanceId) {
- ScheduledFuture task = this.serviceHeartbeats.get(instanceId);
- if (task != null) {
- task.cancel(true);
- }
- this.serviceHeartbeats.remove(instanceId);
- this.registeredServices.remove(instanceId);
- }
-
- static class ConsulHeartbeatTask implements Runnable {
-
- private final String serviceId;
-
- private final String checkId;
-
- private final TtlScheduler ttlScheduler;
-
- private final Supplier statusSupplier;
-
- ConsulHeartbeatTask(String serviceId, TtlScheduler ttlScheduler, Supplier statusSupplier) {
- this.serviceId = serviceId;
- if (!this.serviceId.startsWith("service:")) {
- this.checkId = "service:" + this.serviceId;
- }
- else {
- this.checkId = this.serviceId;
- }
- this.statusSupplier = statusSupplier;
- this.ttlScheduler = ttlScheduler;
- }
-
- @Override
- public void run() {
- ConsulClient client = this.ttlScheduler.client;
- CheckStatus status = statusSupplier.get();
- switch (status) {
- case PASSING:
- possiblyReregisterIfFails(() -> client.agentCheckPass(checkId, null,
- this.ttlScheduler.discoveryProperties.getAclToken()));
- logHeartbeatSent(status);
- break;
- case WARNING:
- possiblyReregisterIfFails(() -> client.agentCheckWarn(checkId, null,
- this.ttlScheduler.discoveryProperties.getAclToken()));
- logHeartbeatSent(status);
- break;
- case CRITICAL:
- possiblyReregisterIfFails(() -> client.agentCheckFail(checkId, null,
- this.ttlScheduler.discoveryProperties.getAclToken()));
- logHeartbeatSent(status);
- break;
- default:
- log.debug(String.format("Not sending consul heartbeat for %s (%s)", checkId, status));
- }
- }
-
- private void logHeartbeatSent(CheckStatus status) {
- log.debug(String.format("Sent consul heartbeat for %s (%s)", checkId, status));
- }
-
- private void possiblyReregisterIfFails(Runnable consulClientCall) {
- try {
- consulClientCall.run();
- }
- catch (OperationException e) {
- if (this.ttlScheduler.heartbeatProperties.isReregisterServiceOnFailure()
- && this.ttlScheduler.reregistrationPredicate.isEligible(e)) {
- log.warn(e.getMessage());
- NewService registeredService = this.ttlScheduler.registeredServices.get(this.serviceId);
- if (registeredService != null) {
- if (log.isInfoEnabled()) {
- log.info("Re-register " + registeredService);
- }
- this.ttlScheduler.client.agentServiceRegister(registeredService,
- this.ttlScheduler.discoveryProperties.getAclToken());
- }
- else {
- log.warn("The service to re-register is not found.");
- }
- }
- else {
- throw e;
- }
- }
- }
-
- }
-
-}
diff --git a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/configclient/ConsulConfigServerAutoConfiguration.java b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/configclient/ConsulConfigServerAutoConfiguration.java
deleted file mode 100644
index 6a7bd206..00000000
--- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/configclient/ConsulConfigServerAutoConfiguration.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.consul.discovery.configclient;
-
-import com.ecwid.consul.v1.ConsulClient;
-import jakarta.annotation.PostConstruct;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
-import org.springframework.boot.context.properties.EnableConfigurationProperties;
-import org.springframework.cloud.config.server.config.ConfigServerProperties;
-import org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.util.StringUtils;
-
-/**
- * Extra configuration for config server if it happens to be registered with Consul.
- *
- * @author Dave Syer
- */
-@Configuration(proxyBeanMethods = false)
-@EnableConfigurationProperties
-@ConditionalOnClass({ ConsulDiscoveryProperties.class, ConsulClient.class, ConfigServerProperties.class })
-public class ConsulConfigServerAutoConfiguration {
-
- /**
- * The metadata key for the path for config server.
- */
- public static final String CONFIG_PATH_KEY = "configPath";
-
- @Autowired(required = false)
- private ConsulDiscoveryProperties properties;
-
- @Autowired(required = false)
- private ConfigServerProperties server;
-
- @PostConstruct
- public void init() {
- if (this.properties == null || this.server == null) {
- return;
- }
- String prefix = this.server.getPrefix();
- if (StringUtils.hasText(prefix)) {
- this.properties.getMetadata().put(CONFIG_PATH_KEY, prefix);
- }
- }
-
-}
diff --git a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/configclient/ConsulConfigServerBootstrapper.java b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/configclient/ConsulConfigServerBootstrapper.java
deleted file mode 100644
index 4773cc51..00000000
--- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/configclient/ConsulConfigServerBootstrapper.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * Copyright 2015-2020 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.consul.discovery.configclient;
-
-import java.util.Collections;
-import java.util.List;
-
-import com.ecwid.consul.v1.ConsulClient;
-import org.apache.commons.logging.Log;
-
-import org.springframework.boot.BootstrapContext;
-import org.springframework.boot.BootstrapRegistry;
-import org.springframework.boot.BootstrapRegistryInitializer;
-import org.springframework.boot.context.properties.bind.BindHandler;
-import org.springframework.boot.context.properties.bind.Bindable;
-import org.springframework.boot.context.properties.bind.Binder;
-import org.springframework.cloud.client.ServiceInstance;
-import org.springframework.cloud.commons.util.InetUtils;
-import org.springframework.cloud.commons.util.InetUtilsProperties;
-import org.springframework.cloud.config.client.ConfigClientProperties;
-import org.springframework.cloud.config.client.ConfigServerInstanceProvider;
-import org.springframework.cloud.consul.ConsulAutoConfiguration;
-import org.springframework.cloud.consul.ConsulProperties;
-import org.springframework.cloud.consul.discovery.ConditionalOnConsulDiscoveryEnabled;
-import org.springframework.cloud.consul.discovery.ConsulDiscoveryClient;
-import org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties;
-import org.springframework.util.ClassUtils;
-
-public class ConsulConfigServerBootstrapper implements BootstrapRegistryInitializer {
-
- @Override
- public void initialize(BootstrapRegistry registry) {
- if (!ClassUtils.isPresent("org.springframework.cloud.config.client.ConfigServerInstanceProvider", null) ||
- // don't run if bootstrap enabled, how to check the property?
- ClassUtils.isPresent("org.springframework.cloud.bootstrap.marker.Marker", null)) {
- return;
- }
- // create consul client
- registry.registerIfAbsent(ConsulProperties.class, context -> {
- Binder binder = context.get(Binder.class);
- if (!isDiscoveryEnabled(binder)) {
- return null;
- }
- return binder.bind(ConsulProperties.PREFIX, Bindable.of(ConsulProperties.class), getBindHandler(context))
- .orElseGet(ConsulProperties::new);
- });
- registry.registerIfAbsent(ConsulClient.class, context -> {
- if (!isDiscoveryEnabled(context.get(Binder.class))) {
- return null;
- }
- ConsulProperties consulProperties = context.get(ConsulProperties.class);
- return ConsulAutoConfiguration.createConsulClient(consulProperties,
- ConsulAutoConfiguration.createConsulRawClientBuilder());
- });
- registry.registerIfAbsent(ConsulDiscoveryClient.class, context -> {
- Binder binder = context.get(Binder.class);
- if (!isDiscoveryEnabled(binder)) {
- return null;
- }
- ConsulClient consulClient = context.get(ConsulClient.class);
- ConsulDiscoveryProperties properties = binder
- .bind(ConsulDiscoveryProperties.PREFIX, Bindable.of(ConsulDiscoveryProperties.class),
- getBindHandler(context))
- .orElseGet(() -> new ConsulDiscoveryProperties(new InetUtils(new InetUtilsProperties())));
- return new ConsulDiscoveryClient(consulClient, properties);
- });
- // promote discovery client if created
- registry.addCloseListener(event -> {
- if (!isDiscoveryEnabled(event.getBootstrapContext().get(Binder.class))) {
- return;
- }
- ConsulDiscoveryClient discoveryClient = event.getBootstrapContext().get(ConsulDiscoveryClient.class);
- if (discoveryClient != null) {
- event.getApplicationContext().getBeanFactory().registerSingleton("consulDiscoveryClient",
- discoveryClient);
- }
- });
-
- // We need to pass the lambda here so we do not create a new instance of
- // ConfigServerInstanceProvider.Function
- // which would result in a ClassNotFoundException when Spring Cloud Config is not
- // on the classpath
- registry.registerIfAbsent(ConfigServerInstanceProvider.Function.class, ConsulFunction::create);
- }
-
- private BindHandler getBindHandler(org.springframework.boot.BootstrapContext context) {
- return context.getOrElse(BindHandler.class, null);
- }
-
- private static boolean isDiscoveryEnabled(Binder binder) {
- return binder.bind(ConfigClientProperties.CONFIG_DISCOVERY_ENABLED, Boolean.class).orElse(false)
- && binder.bind(ConditionalOnConsulDiscoveryEnabled.PROPERTY, Boolean.class).orElse(true)
- && binder.bind("spring.cloud.discovery.enabled", Boolean.class).orElse(true);
- }
-
- /*
- * This Function is executed when loading config data. Because of this we cannot rely
- * on the BootstrapContext because Boot has not finished loading all the configuration
- * data so if we ask the BootstrapContext for configuration data it will not have it.
- * The apply method in this function is passed the Binder and BindHandler from the
- * config data context which has the configuration properties that have been loaded so
- * far in the config data process.
- *
- * We will create many of the same beans in this function as we do above in the
- * initializer above. We do both to maintain compatibility since we are promoting
- * those beans to the main application context.
- */
- static final class ConsulFunction implements ConfigServerInstanceProvider.Function {
-
- private final BootstrapContext context;
-
- private ConsulFunction(BootstrapContext context) {
- this.context = context;
- }
-
- public static ConsulFunction create(BootstrapContext context) {
- return new ConsulFunction(context);
- }
-
- @Override
- public List apply(String serviceId) {
- return apply(serviceId, null, null, null);
- }
-
- @Override
- public List apply(String serviceId, Binder binder, BindHandler bindHandler, Log log) {
- if (binder == null || !isDiscoveryEnabled(binder)) {
- return Collections.emptyList();
- }
-
- ConsulProperties consulProperties = binder
- .bind(ConsulProperties.PREFIX, Bindable.of(ConsulProperties.class), bindHandler)
- .orElseGet(ConsulProperties::new);
- ConsulClient consulClient = ConsulAutoConfiguration.createConsulClient(consulProperties,
- ConsulAutoConfiguration.createConsulRawClientBuilder());
- ConsulDiscoveryProperties properties = binder
- .bind(ConsulDiscoveryProperties.PREFIX, Bindable.of(ConsulDiscoveryProperties.class), bindHandler)
- .orElseGet(() -> new ConsulDiscoveryProperties(new InetUtils(new InetUtilsProperties())));
- ConsulDiscoveryClient discoveryClient = new ConsulDiscoveryClient(consulClient, properties);
-
- return discoveryClient.getInstances(serviceId);
- }
-
- }
-
-}
diff --git a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/configclient/ConsulDiscoveryClientConfigServiceBootstrapConfiguration.java b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/configclient/ConsulDiscoveryClientConfigServiceBootstrapConfiguration.java
deleted file mode 100644
index 633ec97d..00000000
--- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/configclient/ConsulDiscoveryClientConfigServiceBootstrapConfiguration.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.consul.discovery.configclient;
-
-import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
-import org.springframework.cloud.config.client.ConfigServicePropertySourceLocator;
-import org.springframework.cloud.consul.ConsulAutoConfiguration;
-import org.springframework.cloud.consul.discovery.ConsulDiscoveryClientConfiguration;
-import org.springframework.cloud.consul.discovery.reactive.ConsulReactiveDiscoveryClientConfiguration;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * Helper for config client that wants to lookup the config server via discovery.
- *
- * @author Spencer Gibb
- * @author Tim Ysewyn
- */
-@ConditionalOnClass(ConfigServicePropertySourceLocator.class)
-@ConditionalOnProperty("spring.cloud.config.discovery.enabled")
-@Configuration(proxyBeanMethods = false)
-@ImportAutoConfiguration({ ConsulAutoConfiguration.class, ConsulDiscoveryClientConfiguration.class,
- ConsulReactiveDiscoveryClientConfiguration.class })
-public class ConsulDiscoveryClientConfigServiceBootstrapConfiguration {
-
-}
diff --git a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/reactive/ConsulReactiveDiscoveryClient.java b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/reactive/ConsulReactiveDiscoveryClient.java
deleted file mode 100644
index 2fb42938..00000000
--- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/reactive/ConsulReactiveDiscoveryClient.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright 2019-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.consul.discovery.reactive;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import com.ecwid.consul.v1.ConsulClient;
-import com.ecwid.consul.v1.QueryParams;
-import com.ecwid.consul.v1.Response;
-import com.ecwid.consul.v1.catalog.CatalogServicesRequest;
-import com.ecwid.consul.v1.health.HealthServicesRequest;
-import com.ecwid.consul.v1.health.model.HealthService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import reactor.core.publisher.Flux;
-import reactor.core.scheduler.Schedulers;
-
-import org.springframework.cloud.client.ServiceInstance;
-import org.springframework.cloud.client.discovery.ReactiveDiscoveryClient;
-import org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties;
-import org.springframework.cloud.consul.discovery.ConsulServiceInstance;
-
-/**
- * Consul version of {@link ReactiveDiscoveryClient}.
- *
- * @author Tim Ysewyn
- * @author Chris Bono
- */
-public class ConsulReactiveDiscoveryClient implements ReactiveDiscoveryClient {
-
- private static final Logger logger = LoggerFactory.getLogger(ConsulReactiveDiscoveryClient.class);
-
- private final ConsulClient client;
-
- private final ConsulDiscoveryProperties properties;
-
- public ConsulReactiveDiscoveryClient(ConsulClient client, ConsulDiscoveryProperties properties) {
- this.client = client;
- this.properties = properties;
- }
-
- @Override
- public String description() {
- return "Spring Cloud Consul Reactive Discovery Client";
- }
-
- @Override
- public Flux getInstances(String serviceId) {
- return Flux.defer(() -> {
- List instances = new ArrayList<>();
- for (HealthService healthService : getHealthServices(serviceId)) {
- instances.add(new ConsulServiceInstance(healthService, serviceId));
- }
- return Flux.fromIterable(instances);
- }).onErrorResume(exception -> {
- logger.error("Error getting instances from Consul.", exception);
- return Flux.empty();
- }).subscribeOn(Schedulers.boundedElastic());
- }
-
- private List getHealthServices(String serviceId) {
- HealthServicesRequest.Builder requestBuilder = HealthServicesRequest.newBuilder()
- .setPassing(properties.isQueryPassing()).setQueryParams(QueryParams.DEFAULT)
- .setToken(properties.getAclToken());
- String[] queryTags = properties.getQueryTagsForService(serviceId);
- if (queryTags != null) {
- requestBuilder.setTags(queryTags);
- }
- HealthServicesRequest request = requestBuilder.build();
-
- Response> services = client.getHealthServices(serviceId, request);
-
- return services == null ? Collections.emptyList() : services.getValue();
- }
-
- @Override
- public Flux getServices() {
- return Flux.defer(() -> {
- CatalogServicesRequest request = CatalogServicesRequest.newBuilder().setToken(properties.getAclToken())
- .setQueryParams(QueryParams.DEFAULT).build();
- Response