Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Intermittent issues with Consul API discovery #301
We observed few things about the way consul discovery behaves -
We are using version 1.5.18 of consul client. Here are the details -
String path = "/v1/health/service/" + serviceName + "?passing&wait=600s&index=" + lastConsulIndex;
If we reduce the wait time to, say 5 seconds (wait=5s), we get response from consul in 5 seconds(again intermittent)
Could you shed some light on our findings? Also, we have few questions around the implementation –
@kumasath you have asked a very interesting question and it put you into the light-4j super user group :)
I have added a section in the https://doc.networknt.com/concern/consul/ but not published yet.
Consul Blocking Queries
For service discovery, we are using Consul Blocking Queries (Long polling). It basically sends a request to the Consul server and tells Consul don't do anything within 10 minutes if the subscribed service instances are not changed. If the subscribed service instances are changed, it will return the result immediately with the changes. After 10 minutes, the request will timeout and a new request will be issued. In this way, we can maintain a list of healthy service instances all the time at the client side. If it is necessary to create a new connection, there is no need to go to Consul for a discovery as the local cache is the latest. This design is the fast way to let the client be notified if any service instance is gracefully shutdown or crashed.