@Override
public Response intercept(Chain chain) throws IOException {
// The original request
Request originalRequest = chain.request();
// If it is possible to do a failover on the first request (as in, one or more
// targets are viable)
if (strategy.isRequestViable(originalRequest)) {
// Initially, we have an inflight request and no response
Request previousRequest = originalRequest;
Response previousResponse = null;
Optional<Request> nextRequest;
// Get the next viable request
while ((nextRequest = strategy.computeNextStage(previousRequest, previousResponse)).isPresent())
// Get the response from the last viable request
try {
// Cache for the next cycle if needed
final Request next = nextRequest.get();
previousRequest = next;
// Anything other than an exception is valid here.
// This is because a 400 series error is a valid code (Permission Denied/Key Not Found)
return chain.proceed(next);
} catch (Exception ex) {
LOGGER.debug("Failed to connect to {}", nextRequest.get().url(), ex);
strategy.markRequestFailed(nextRequest.get());
}
throw new ConsulException("Unable to successfully determine a viable host for communication.");
} else
throw new ConsulException("Consul failover strategy has determined that there are no viable hosts remaining.");
}
we can see 'if (strategy.isRequestViable(originalRequest))' goes first in this function , therefore for 'BlacklistingConsulFailoverStrategy' it will never be able to recover even if any consul instance recover.
@Override
public boolean isRequestViable(Request current) {
return (targets.size() > blacklist.size()) || !blacklist.containsKey(fromRequest(current));
}