'Feign client : Load balancer does not have available server for client
I'm working on a microservice architecture, I'm using Feign client to make a rest call to another microservice. I using spring boot version 2.1.3.RELEASE
and spring cloud: Greenwich.SR3
.
here is my feign client:
Proxy interface:
import java.util.List;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import relevebancaire.workflow.activiti.model.ReleveBancaire;
@FeignClient(name = "activiti-workflow")
public interface ActivitiWorkflowProxy {
@GetMapping("/relevebancaire/{relevebancaireId}")
public ReleveBancaire getReleveBancaireById(@PathVariable Long relevebancaireId);
}
Feing controller:
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import relevebancaire.workflow.activiti.model.ReleveBancaire;
import relevebancaire.workflow.activiti.proxy.ActivitiWorkflowProxy;
@RestController
public class ActivitiController {
@Autowired
ActivitiWorkflowProxy activitiWorkflowProxy;
@GetMapping("/relevebancaire/{relevebancaireId}")
ResponseEntity<ReleveBancaire> getReleveBancaireById(@PathVariable Long relevebancaireId){
return new ResponseEntity<>(activitiWorkflowProxy.getReleveBancaireById(relevebancaireId), HttpStatus.OK);
}
}
Spring boot application:
@SpringBootApplication
@EnableFeignClients
@EnableEurekaClient
@EnableDiscoveryClient
public class ActivitiWorkflowBootloader {
public static void main(String[] args) {
SpringApplication.run(ActivitiWorkflowBootloader.class, args);
}
}
Application.properties:
ribbon.eureka.enabled=true
server.port=8081
spring.application.name=activiti-workflow
activiti-workflow.ribbon.listOfServers = http://localhost:8081
Error:
2022-04-21 05:23:31.626 ERROR 3956 --- [nio-8081-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.RuntimeException: com.netflix.client.ClientException: Load balancer does not have available server for client: activiti-workflow] with root cause
com.netflix.client.ClientException: Load balancer does not have available server for client: activiti-workflow
at com.netflix.loadbalancer.LoadBalancerContext.getServerFromLoadBalancer(LoadBalancerContext.java:483) ~[ribbon-loadbalancer-2.3.0.jar:2.3.0]
at com.netflix.loadbalancer.reactive.LoadBalancerCommand$1.call(LoadBalancerCommand.java:184) ~[ribbon-loadbalancer-2.3.0.jar:2.3.0]
at com.netflix.loadbalancer.reactive.LoadBalancerCommand$1.call(LoadBalancerCommand.java:180) ~[ribbon-loadbalancer-2.3.0.jar:2.3.0]
at rx.Observable.unsafeSubscribe(Observable.java:10327) ~[rxjava-1.3.8.jar:1.3.8]
I've searched all over stackoverflow and implemented a lot of solutions out there and nothing solved this. I even used all the solutions on this question: Load balancer does not have available server for client but nothing. Any help please.
Solution 1:[1]
If you have Eureka on the classpath, by default the Ribbon client inside Feign uses the Eureka server list, and not the one from the <feign-client>.ribbon.listOfServers
property.
To change this you either have to turn off Eureka support in Ribbon by setting ribbon.eureka.enabled=false
or use the programmatic server list configuration, e.g.
@Bean
public ServerList<Server> ribbonServerList() {
return new ConfigurationBasedServerList();
// or new StaticServerList<>(new Server("activiti-workflow", 80));
}
Reference: https://github.com/spring-cloud/spring-cloud-netflix/issues/564
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | dekkard |