Add the option to only query for services that are passing health checks.
This commit is contained in:
@@ -110,7 +110,7 @@ public class ConsulDiscoveryClient implements DiscoveryClient {
|
||||
|
||||
private void addInstancesToList(List<ServiceInstance> instances, String serviceId) {
|
||||
Response<List<HealthService>> services = client.getHealthServices(serviceId,
|
||||
false, QueryParams.DEFAULT);
|
||||
this.properties.isQueryPassing(), QueryParams.DEFAULT);
|
||||
for (HealthService service : services.getValue()) {
|
||||
String host = findHost(service);
|
||||
instances.add(new DefaultServiceInstance(serviceId, host, service
|
||||
|
||||
@@ -114,6 +114,12 @@ public class ConsulDiscoveryProperties {
|
||||
*/
|
||||
private Map<String, String> serverListQueryTags = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Add the 'passing` parameter to /v1/health/service/serviceName.
|
||||
* This pushes health check passing to the server.
|
||||
*/
|
||||
private boolean queryPassing = false;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private ConsulDiscoveryProperties() {}
|
||||
|
||||
|
||||
@@ -58,12 +58,13 @@ public class ConsulServerList extends AbstractServerList<ConsulServer> {
|
||||
}
|
||||
|
||||
private List<ConsulServer> getServers() {
|
||||
if (client == null) {
|
||||
if (this.client == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
String tag = getTag(); // null is ok
|
||||
Response<List<HealthService>> response = client.getHealthServices(
|
||||
this.serviceId, tag, false, QueryParams.DEFAULT);
|
||||
Response<List<HealthService>> response = this.client.getHealthServices(
|
||||
this.serviceId, tag, this.properties.isQueryPassing(),
|
||||
QueryParams.DEFAULT);
|
||||
if (response.getValue() == null || response.getValue().isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user