How to override value of ribbon.serverListRefreshInterval value in Spring Cloud Ribbon?

I wrote a simple Spring Cloud Ribbon program to call the REST service that was registered with Eureka.

But how to override the value of ribbon.serverListRefreshInterval ? The default value is 30 seconds, I would like to reduce the time interval.

Thanks in advance.

+5
source share
2 answers

Try:

 myService.ribbon.ServerListRefreshInterval=10000 

where myService is the name of your target microservice.

UPDATE

After some digging of the source code, it turned out that LoadBalancerBuilder calls:

 @Deprecated public ZoneAwareLoadBalancer(IClientConfig clientConfig, IRule rule, IPing ping, ServerList<T> serverList, ServerListFilter<T> filter) { super(clientConfig, rule, ping, serverList, filter); } 

whose super:

 @Deprecated public DynamicServerListLoadBalancer(IClientConfig clientConfig, IRule rule, IPing ping, ServerList<T> serverList, ServerListFilter<T> filter) { this( clientConfig, rule, ping, serverList, filter, new PollingServerListUpdater() ); } 

Check out the PollingServerListUpdater constructors:

 private static int LISTOFSERVERS_CACHE_REPEAT_INTERVAL = 30 * 1000; // msecs; public PollingServerListUpdater() { this(LISTOFSERVERS_CACHE_UPDATE_DELAY, LISTOFSERVERS_CACHE_REPEAT_INTERVAL); } public PollingServerListUpdater(IClientConfig clientConfig) { this(LISTOFSERVERS_CACHE_UPDATE_DELAY, getRefreshIntervalMs(clientConfig)); } 

The second method will allow us to override the default update interval. However, this is the first one that called, so it ignores the property.

UPDATE 2:

There is an open question about this: https://github.com/spring-cloud/spring-cloud-netflix/issues/1304

+3
source

@codependent

After installing the below configuration in application.yml, he looked that the configuration did not take effect.

 Compute-Service: ribbon: ServerListRefreshInterval: 1000 

I noticed that the list of instances was updated on the tape side (via the eureka.client.registry-fetch-interval-seconds parameter), however the tape still indicates a dead instance:

 [tbeatExecutor-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_RIBBON-CONSUMER/192.168.1.101:Ribbon-Consumer:3333 - Heartbeat status: 200 [freshExecutor-0] com.netflix.discovery.DiscoveryClient : Got delta update with apps hashcode UP_2_ [freshExecutor-0] com.netflix.discovery.DiscoveryClient : Added instance 192.168.1.101:Ribbon-Consumer:3333 to the existing apps in region null [freshExecutor-0] com.netflix.discovery.DiscoveryClient : Deleted instance 192.168.1.101:Compute-Service:2222 to the existing apps [freshExecutor-0] com.netflix.discovery.DiscoveryClient : Added instance 192.168.1.101:Compute-Service:1111 to the existing apps in region null [freshExecutor-0] com.netflix.discovery.DiscoveryClient : The total number of instances fetched by the delta processor : 3 [freshExecutor-0] com.netflix.discovery.DiscoveryClient : The total number of all instances in the client now is 2 [freshExecutor-0] com.netflix.discovery.DiscoveryClient : Completed cache refresh task for discovery. All Apps hash code is Local region apps hashcode: UP_2_, is fetching remote regions? false [nio-3333-exec-3] oaccC[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://Compute-Service/add": Connection refused; nested exception is java.net.ConnectException: Connection refused] with root cause 

192.168.1.101:Compute-Service:1111 was the right instance of the service, while 192.168.1.101:Compute-Service:2222 was the dead instance, obviously the tape was still pointing to the dead instance, which means the cache server Ribbon ServerList was not updated.

+2
source

All Articles