0

I have a Spring Boot application which serves as a Eureka client. The application has the need to call another micro-service through REST, and I wish to make this call using Feign. The issue I am having is, my application is trying to lookup the service name in Eureka, when it is only defined in my applications yaml file.

I apologize for the hard to follow explanation, hopefully the following code snippets will help clarify.

Feign client:

@FeignClient("foo")
@Component
public interface FooServiceProxy{
    @RequestMapping(value = "/balance", method = RequestMethod.POST, produces = "application/json")
    ServiceResponse execute(ServiceRequest serviceRequest);
}

In my controller who calls this Feign client, the FooServiceProxy is defined using @AutoWired:

@Autowired
private FooServiceProxy fooServiceProxy;

My yaml file is as follows:

spring:
    application:
        name: app-name

server:
port: 8080

foo:
    ribbon:
        listOfServers: http://hostname:8081/balance

eureka:
  client:
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://eurekasrver:8761/eureka/

My issue is, during run-time, the following error is thrown: java.lang.RuntimeException: com.netflix.client.ClientException: Load balancer does not have available server for client: foo

Interestingly, if I remove the @EnableEurekaClient annotation from the application, everything works. I believe I understand the problem which is that instead of looking up the server for foo in my yaml file, because the application is a Eureka client, Feign is going straight to Eureka to lookup a server ip, then failing as none can be found. Despite seeming to understand the problem, I have been unable to find a solution online or to think of one myself.

Any help will be appreciated. Thank you!

dFrancisco
  • 896
  • 1
  • 11
  • 21

1 Answers1

1

Concerning this question, you should take in account that when eureka is on your classpath, all ribbon configuration are charged by eureka, so it'll use eureka server's list.

Spring Cloud uses @RibbonClient to configure the types used by ribbon, like server list. If you have eureka on the classpath, by default it uses the eureka server list (hence your need for the flag to disable eureka). Commented by spencergibb https://github.com/spring-cloud/spring-cloud-netflix/issues/564

You can try either by adding the NIWSServerListClassName configuration:

`someservice.ribbon: 
   NIWSServerListClassName:com.netflix.loadbalancer.ConfigurationBasedServerList  
   listOfServers: server1:80`

Or try the solution proposed in this issue https://github.com/spring-cloud/spring-cloud-netflix/issues/564

arcticless
  • 664
  • 5
  • 14