Alexander
Alexander

Reputation: 391

Feign client manually. Load balancer does not have available server for client

I have two services registered with eureka. Service C calls service A. Service C is feign client. I want implement feign client manually. But I catch an exception:

com.netflix.client.ClientException: Load balancer does not have available server for client: service-test-a

Application class:

@EnableEurekaClient
@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

Feign interface:

@Component
public interface FeignService {
    @RequestLine("GET /")
    public String getServiceA();
}

Feign config:

@Configuration
@Import(FeignClientsConfiguration.class)
public class MyConfig {

}

Controller:

@RestController
public class Controller {

    private FeignService feignService;

    @Autowired
    public void Controller() {
        feignService = Feign.builder()
                .client(RibbonClient.create())
                .target(FeignService.class, "http://service-test-a");
    }

    @RequestMapping(value = "/build", method = RequestMethod.GET)
    public String getServiceC() {
        return feignService.getServiceA();
    }
}

What am I doing wrong?

Upvotes: 1

Views: 5457

Answers (1)

yongsung.yoon
yongsung.yoon

Reputation: 5589

AFAIK, there is no easy way of using OpenFeign with eureka. There is no guide or example for that. Also I guess that it may require some additional implementations and configuration.

Instead, please try to use Spring Cloud Feign. It provides full integration with eureka and ribbon without any additional implementation. You can use Spring Cloud Feign with just a few changes in your above code.

Please refer to Spring Cloud Feign

Upvotes: 2

Related Questions