Search code examples
netflix-feign

Which order does FeignClient discover services?


I have two instances for a first service. They work on different ports and have the same names. These services are registered with Eureka. Also I have a second service which need discover one instance of the first service. The second service is implemented with FeignClient and registred with Eureka too. Every time the second service discover an instance of the first service on the random order.

Which principle discovering services has FeignClient? Which instance will FeignClient choose if it will discover more than one instances of the first service?

If I use DiscoveryClient instead FeignClient I can get a list of the service instances and choose the first instance or choose the instance with custom metadata.

What about FeignClient?


Solution

  • I think I have found an answer. Ribbon manage choosing an eligible service. For example we can see it on follow code:

     public Optional<Server> chooseRoundRobinAfterFiltering(List<Server> servers, Object loadBalancerKey) {
            List<Server> eligible = getEligibleServers(servers, loadBalancerKey);
            if (eligible.size() == 0) {
                return Optional.absent();
            }
            return Optional.of(eligible.get(nextIndex.getAndIncrement() % eligible.size()));
        }
    

    We have list of eligible servers and choosing one of them is a simple logic.