如何覆盖Spring Cloud Ribbon中的ribbon.serverListRefreshInterval默认值? [英] How to override the ribbon.serverListRefreshInterval default value in Spring Cloud Ribbon?

查看:1104
本文介绍了如何覆盖Spring Cloud Ribbon中的ribbon.serverListRefreshInterval默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个简单的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默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆