1

I am unable to configure a @FeignClient with a list of servers to use. I am using Spring Cloud Netflix, but this particular service (foo-service) does not register with Eureka. For this reason I need to configure a list of servers, for foo-service in a YML file.

However, the listOfServers is never read, and so the operation fails as Feign/Ribbon does not have a single server to use.

What am I doing wrong here?

My Feign client:

@FeignClient(name="foo-service")
public interface FooFeignClient {

   @RequestMapping(value = "/perform-check", method = POST)
   ResponseEntity<FooResponse> performCheck(FooRequest fooRequest);

}

In bootstrap.yml:

foo-service:
   ribbon:
      eureka:
         enabled: false
      listOfServers: foobox1,foobox2,foobox3

How the Feign client is configured in the Spring Boot application:

@SpringBootApplication
@EnableEurekaClient
@EnableDiscoveryClient
@EnableHazelcastClient
@EnableFeignClients
@RibbonClients({
   @RibbonClient(name = "foo-service", configuration = MyApp.FooServiceRibbonConfig.class)
})
public class MyApp {

   public static void main(String[] args) {
      SpringApplication.run(MyApp.class, args);
   }

   ....

   @Configuration
   static class FooServiceRibbonConfig {

      @Bean
      @ConditionalOnMissingBean
      public IClientConfig ribbonClientConfig() {
         DefaultClientConfigImpl config = new DefaultClientConfigImpl();
         config.loadProperties("foo-service");
         return config;
      }

      @Bean
      ServerList<Server> ribbonServerList(IClientConfig config) {
         ConfigurationBasedServerList serverList = new ConfigurationBasedServerList();
         serverList.initWithNiwsConfig(config);
         return serverList;
      }
   }
}
g00glen00b
  • 41,995
  • 13
  • 95
  • 133
vegemite4me
  • 6,621
  • 5
  • 53
  • 79
  • `listOfServers` is case sensitive and should be `ListOfServers`. – spencergibb May 17 '17 at 18:11
  • @spencergibb `ListOfServers` did not work either. I was trying to follow the advice here https://github.com/spring-cloud/spring-cloud-netflix/issues/325 – vegemite4me May 18 '17 at 08:58
  • you'll need to provide a sample project that recreates the problem. – spencergibb May 18 '17 at 16:21
  • @spencergibb I still have the same problem as the author. If I may, here's a sample project to reproduce the error: https://github.com/RaviH/spring-cloud-feign-demo You should see this message when you execute the `DemoServiceTest`: `Load balancer does not have available server for client: demoservice` – user770119 May 14 '18 at 22:08

1 Answers1

0

The easiest way to achieve your needs is..

In your code, remove all code related to FooServiceRibbonConfig like below.

@SpringBootApplication
@EnableEurekaClient
@EnableDiscoveryClient
@EnableHazelcastClient
@EnableFeignClients
})
public class MyApp {

   public static void main(String[] args) {
      SpringApplication.run(MyApp.class, args);
   }
   ....
}

And then change your profile files like below.

foo-service:
   ribbon:
      NIWSServerListClassName: com.netflix.loadbalancer.ConfigurationBasedServerList
      listOfServers: foobox1,foobox2,foobox3

Defining ribbonServerList bean like you did is another way to achieve that, and I'm not sure why your code is not running. In my case, similar code like yours works well. But there is a easier way, so please try it.

yongsung.yoon
  • 5,489
  • 28
  • 32
  • 2
    I get the same exception: `java.lang.RuntimeException: com.netflix.client.ClientException: Load balancer does not have available server for client: foo-service`. It's as if the YML file is not read at all. – vegemite4me May 18 '17 at 09:07