Search code examples
spring-bootspring-cloudspring-cloud-feign

How to create multiple @FeignClient each with its own listOfServers while using BlockingLocadBalancerCient


I'm trying to use Spring Cloud Open Feign following the documentation. I don't want to use Eureka. I want to configure a list of servers in my application.yml.

How To Include Feign

If you don’t want to use Eureka, you can simply configure a list of servers in your external configuration (see above for example)

The link is to the same page. There is no example.

Ribbon is in maintenance mode and the recommendation from Spring is to turn it off. By doing so BlockingLoadBalancerClient will be used instead.

In my case I have 2 feign clients. @FeignClient("serviceA") & @FeignClient("serviceB"). How can I use different list of servers for each of my feign clients. I tried to manully create 2 @Bean of ServiceInstanceListSupplier one for each feign client This caused

could not be registered. A bean with that name has already been defined

Solution

  • Use the simple discovery client which is properties driven.

    spring.cloud.discovery.client.simple.instances.service1[0].uri=http://s11:8080
    spring.cloud.discovery.client.simple.instances.service1[1].uri=https://s12:8443
    spring.cloud.discovery.client.simple.instances.service2[0].uri=https://s21:8080
    spring.cloud.discovery.client.simple.instances.service2[1].uri=https://s22:443