问题描述
我编写了一个简单的Spring Cloud Ribbon应用程序,以调用已在Eureka中注册的REST服务.
I wrote a simple Spring Cloud Ribbon application, to call a REST service which was registered in Eureka.
但是如何覆盖ribbon.serverListRefreshInterval
值?默认值为30秒,我想减少时间间隔.
But how to override the ribbon.serverListRefreshInterval
value? The default value is 30 seconds, I'd like to reduce the time interval.
谢谢.
推荐答案
尝试使用:
myService.ribbon.ServerListRefreshInterval=10000
其中myService
是目标微服务的名称.
where myService
is the name of your destination microservice.
更新:
经过一些源代码的挖掘,我发现LoadBalancerBuilder
会调用:
After some source code digging I found 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);
}
超级是:
@Deprecated
public DynamicServerListLoadBalancer(IClientConfig clientConfig, IRule rule, IPing ping,
ServerList<T> serverList, ServerListFilter<T> filter) {
this(
clientConfig,
rule,
ping,
serverList,
filter,
new PollingServerListUpdater()
);
}
注意PollingServerListUpdater
构造函数:
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));
}
第二个将允许我们覆盖默认的刷新间隔.但是,它是第一个被调用的,因此它将忽略de property.
The second one would allow us to override the default refresh interval. However it's the first one that's called, so it ignores de property.
更新2:
对此存在一个公开的问题: https://github.com/spring-cloud/spring-cloud-netflix/issues/1304
There's an open issue about this: https://github.com/spring-cloud/spring-cloud-netflix/issues/1304
这篇关于如何覆盖Spring Cloud Ribbon中的ribbon.serverListRefreshInterval默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!