Gh 304 add discovery clients order support (#446)
NOTE: This can only be merged after https://github.com/spring-cloud/spring-cloud-commons/pull/412 is has been merged.
This commit is contained in:
committed by
Spencer Gibb
parent
8150eb0597
commit
ad8938d491
@@ -59,7 +59,7 @@ public class ConsulDiscoveryClient implements DiscoveryClient {
|
||||
|
||||
@Deprecated
|
||||
public ConsulDiscoveryClient(ConsulClient client, ConsulDiscoveryProperties properties,
|
||||
LocalResolver localResolver) {
|
||||
LocalResolver localResolver) {
|
||||
this(client, properties);
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ public class ConsulDiscoveryClient implements DiscoveryClient {
|
||||
}
|
||||
|
||||
public List<ServiceInstance> getInstances(final String serviceId,
|
||||
final QueryParams queryParams) {
|
||||
final QueryParams queryParams) {
|
||||
List<ServiceInstance> instances = new ArrayList<>();
|
||||
|
||||
addInstancesToList(instances, serviceId, queryParams);
|
||||
@@ -83,7 +83,7 @@ public class ConsulDiscoveryClient implements DiscoveryClient {
|
||||
}
|
||||
|
||||
private void addInstancesToList(List<ServiceInstance> instances, String serviceId,
|
||||
QueryParams queryParams) {
|
||||
QueryParams queryParams) {
|
||||
|
||||
String aclToken = properties.getAclToken();
|
||||
Response<List<HealthService>> services;
|
||||
@@ -99,11 +99,11 @@ public class ConsulDiscoveryClient implements DiscoveryClient {
|
||||
}
|
||||
for (HealthService service : services.getValue()) {
|
||||
String host = findHost(service);
|
||||
|
||||
Map<String,String> metadata = getMetadata(service);
|
||||
|
||||
Map<String, String> metadata = getMetadata(service);
|
||||
boolean secure = false;
|
||||
if(metadata.containsKey("secure")) {
|
||||
secure = Boolean.parseBoolean(metadata.get("secure"));
|
||||
if (metadata.containsKey("secure")) {
|
||||
secure = Boolean.parseBoolean(metadata.get("secure"));
|
||||
}
|
||||
instances.add(new DefaultServiceInstance(serviceId, host, service
|
||||
.getService().getPort(), secure, metadata));
|
||||
@@ -133,4 +133,9 @@ public class ConsulDiscoveryClient implements DiscoveryClient {
|
||||
.keySet());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return this.properties.getOrder();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
* @author Olga Maciaszek-Sharma
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnConsulEnabled
|
||||
|
||||
@@ -164,6 +164,11 @@ public class ConsulDiscoveryProperties {
|
||||
*/
|
||||
private Boolean healthCheckTlsSkipVerify;
|
||||
|
||||
/**
|
||||
* Order of the discovery client used by `CompositeDiscoveryClient` for sorting available clients.
|
||||
*/
|
||||
private int order = 0;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private ConsulDiscoveryProperties() {}
|
||||
|
||||
@@ -464,6 +469,14 @@ public class ConsulDiscoveryProperties {
|
||||
this.healthCheckTlsSkipVerify = healthCheckTlsSkipVerify;
|
||||
}
|
||||
|
||||
public int getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
public void setOrder(int order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ConsulDiscoveryProperties{" +
|
||||
@@ -502,6 +515,7 @@ public class ConsulDiscoveryProperties {
|
||||
", registerHealthCheck=" + registerHealthCheck +
|
||||
", failFast=" + failFast +
|
||||
", healthCheckTlsSkipVerify=" + healthCheckTlsSkipVerify +
|
||||
", order=" + order +
|
||||
'}';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user