-
Notifications
You must be signed in to change notification settings - Fork 540
Description
Looking at the ConsulServerList code, it wouldn't be super hard to enable a failover on a refresh of datacenter to fallback to a remote dc. Thinking something like this in
Add application property:
"spring.cloud.consul.discovery.fallbackDatacenters=us-west-1"
org.springframework.cloud.consul.discovery.ConsulServerList:
private List<ConsulServer> getServers() {
if (this.client == null) {
return Collections.emptyList();
}
String tag = getTag(); // null is ok
Response<List<HealthService>> response = this.client.getHealthServices(
this.serviceId, tag, this.properties.isQueryPassing(),
createQueryParamsForClientRequest(), this.properties.getAclToken());
if (response.getValue() == null || response.getValue().isEmpty()) {
return transformResponse(fallBackToOtherDCOrEmpty());
}
return transformResponse(response.getValue());
}
private List<HealthService> fallBackToOtherDCOrEmpty() {
Response<List<HealthService>> response = this.client.getHealthServices(
this.serviceId, tag, this.properties.isQueryPassing(),
new QueryParams(this.properties.getFallbackDatacenters()[0], this.properties.getAclToken())
return response.getValue() == null ? Collections.emtpyList() ? esponse.getValue();
}
PURE thought process at this - but would enable you to configure a fallbackDatacenter property which would allow if a service had no health hosts, to automatically go to a fallback datacenter. I could see it being a recursive array through the available fallbacks. Another option would be to use prepared Queries in consul vs. trying to write it here, but would have to change how healthy services were discovered.
Thoughts? Other ways to implement this?