Add the option to only query for services that are passing health checks.

This commit is contained in:
Spencer Gibb
2016-02-24 16:45:41 -07:00
parent db62855c22
commit 3f3fccd01a
3 changed files with 11 additions and 4 deletions

View File

@@ -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

View File

@@ -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() {}

View File

@@ -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();
}