Skip to content

RFE: Failover to another DC for service discovery list #444

@jasonmcintosh

Description

@jasonmcintosh

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions