Как переопределить значение по умолчанию tape.serverListRefreshInterval в Spring Cloud Ribbon?

Я написал простое приложение Spring Cloud Ribbon для вызова службы REST, зарегистрированной в Eureka.

Но как изменить значение ribbon.serverListRefreshInterval? Значение по умолчанию - 30 секунд, хотелось бы уменьшить временной интервал.

Заранее спасибо.


person Anson Wang    schedule 19.09.2016    source источник


Ответы (2)


Попробуйте:

myService.ribbon.ServerListRefreshInterval=10000

где myService - имя целевого микросервиса.

ОБНОВЛЕНИЕ:

Покопавшись в исходном коде, я обнаружил, что LoadBalancerBuilder вызывает:

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

Второй позволит нам переопределить интервал обновления по умолчанию. Однако он вызывается первым, поэтому он игнорирует свойство.

ОБНОВЛЕНИЕ 2:

По этому поводу есть открытый вопрос: https://github.com/spring-cloud/spring-cloud-netflix/issues/1304

person codependent    schedule 19.09.2016
comment
Ваш сервис зарегистрирован точно как Compute-Service на вашем сервере Eureka? Обратите внимание на заглавные буквы. - person codependent; 19.09.2016
comment
Конечно, дважды проверил, нет ли ошибки опечатки, позже приложу несколько снимков экрана для справки. - person Anson Wang; 19.09.2016
comment
Спасибо за ценный ответ, надеюсь, что ошибку можно будет исправить как можно скорее. - person Anson Wang; 21.09.2016

@codependent

После того, как вы поместили конфигурацию ниже в application.yml, казалось, что конфигурация не вступила в силу.

Compute-Service:   
  ribbon:  
    ServerListRefreshInterval: 1000

Я заметил, что список экземпляров был обновлен на стороне ленты (с помощью параметра eureka.client.registry-fetch-interval-seconds), однако лента по-прежнему указывает на мертвый экземпляр:

[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] o.a.c.c.C.[.[.[/].[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 был правильным экземпляром службы, а 192.168.1.101:Compute-Service:2222 был мертвым экземпляром, очевидно, Ribbon все еще указывал на мертвый экземпляр, что означало, что кеш Ribbon ServerList не обновлялся.

person Anson Wang    schedule 19.09.2016