spring-bootribbonspring-cloud-feignfeignnetflix-ribbon

How to specify Ribbon Configuration for a specific Feign client in a Spring Boot project having multiple Feign clients?


I have a spring boot project which is having two Feign Client's.
First Feign client (i.e. ServiceAProxy.class below), which will work on Service Discovery using Eureka or Consul.

@FeignClient(name="service-A")
public interface ServiceAProxy{
   @RequestMapping(method= RequestMethod.GET)
   String getResponse();
}

Second Feign client( i.e ServiceBProxy.class ), needs to have a set of server list which will be picked from Spring Cloud Configuration server or Apache zookeeper config server and will be passed to the ribbon client of ServiceBProxy.class. For that, I'm trying to add a Ribbon Client Configuration that will modify the ribbon server list. Below is the code for the second feign client.

@FeignClient(name="service-B")
@RibbonClient(name="service-B",configuration= ServiceBProxy.LocalRibbonClientConfig.class)
public interface ServiceBProxy{
   @RequestMapping(method = RequestMethod.GET)
   String invalidateUsers();



@Configuration
class LocalRibbonClientConfig{
    
     @Value("${server-host1}") // fetched from config
     private String host1;

     @Value("${server-host2}") // fetched from config
     private String host2;


    @Bean
    public ServerList<Server> ribbonServerList() {
      return new StaticServerList<>(
              new Server(host1,8080),
              new Server(host2,8081)
      );
    }
}


}



Now, when I run the code, ServiceBProxy.class works as expected and picks the list of servers that was specified in the LocalRibbonClientConfig.class.
But the problem is with the ServiceAProxy.class which was suppose to work on the basis of service discovery also starts to use the LocalRibbonClientConfig.

How can I only allow ServiceBProxy.class to use the custom ribbon configurations and other feign clients in the project to work as per their default behaviour.

Please guide on this.


Solution

  • wonder if you have tried contextId

    @FeignClient(contextId = "fooClient", name = "stores", configuration = FooConfiguration.class)
    

    https://cloud.spring.io/spring-cloud-netflix/multi/multi_spring-cloud-feign.html