Giter Club home page Giter Club logo

consul-client's Introduction

  • 👋 Hi, I’m Gary Liao. This is my account @gary258796.
  • 👀 I’m interested in Java, Spring development.
  • 😆 Working as a java backend engineer about 2 years now.
  • 🌱 I’m currently learning Docker and Cloud platform.

consul-client's People

Contributors

adericbourg avatar alesharik avatar alespuh avatar alugowski avatar art4noir avatar cbarbara-okta avatar cschroed-usgs avatar hansenc avatar heanssgen-troy avatar heruv1m avatar hrmohr avatar isuftin avatar jeinwag avatar jplock avatar killerwhile avatar lburgazzoli avatar maqdev avatar odiszapc avatar rickfast avatar robbert229 avatar robinmeiss avatar shuraa avatar sshankar avatar studouglas-scx avatar thongsav-usgs avatar tipnik avatar vascokk avatar weberr13 avatar yannrobert avatar yfouquet avatar

Stargazers

 avatar

consul-client's Issues

ConsulFailoverInterceptor always throw Exception when ConsulFailoverStrategy isRequestViable return false

Below is the intercept code snippet of ConsulFailoverInterceptor

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

Maybe find some place to let instance removed from blacklist ??

When using withFailoverInterceptor , the default url is still localhost:8500

Since withFailoverInterceptor only config the consulFailoverInterceptor with send in strategy, the default url isn't changed.
So currently, we have to call also ‘withHostAndPort’ or 'withMultipleHostAndPort' or 'withUrl' when configuring.

Which will makes the code like so


 Consul.builder()
             .withMultipleHostAndPort(consulHosts, 60000)
             .withFailoverInterceptor(new BlacklistingConsulWithRecoverFailoverStrategy(consulHosts, 60000))
             .build();

The best is to modify the api here , to make it more clean for what it supposed to do?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.