Skip to content
Advertisement

Spring cloud : Can not get Feign client to work with consul

I am trying to set up a simple spring cloud consul app.

I have a “distribution” service up and registered in consul (with the spring.application.name property set to “distribution”)

I have an “acquisition” service that is trying to make a call to the “distribution” service using feign.

Here is my main class

@Configuration
@EnableAutoConfiguration
@EnableDiscoveryClient
@RestController
@EnableFeignClients
@EnableHystrix
public class Acquisition {


    @Autowired
    private DiscoveryClient discoveryClient;

    @Autowired
    private DistributionClient distributionClient;


    @RequestMapping("/use-feign")
    public String sendData() {
        distributionClient.sendData(new Data("Hello World"));
        return "sent";
    }

    @RequestMapping("/disco")
    public String disco() {
         List<ServiceInstance> list = discoveryClient.getInstances("distribution");
        if (list != null && list.size() > 0) {
            return list.get(0).getUri().toString();
        }
        return null;
    }

    public static void main(String[] args) {
        SpringApplication.run(Acquisition.class, args);
    }

}

here is my feign client

@FeignClient(value = "distribution")
interface DistributionClient {

    @RequestMapping(method = RequestMethod.POST, value = "/data", consumes = "application/json")
    void sendData(Data data);
}

and here is my pom.xml

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-consul-all</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-feign</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-hystrix</artifactId>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-consul-dependencies</artifactId>
            <version>1.0.1.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

When I request the “/disco” Url, the url of the “distribution” service is properly retrieved, which means that the whole discovery thing is working as expected.

But, when I request the “/use-feign” url, I get the following exception :

com.netflix.client.ClientException: Load balancer does not have available server for client: distribution at com.netflix.loadbalancer.LoadBalancerContext.getServerFromLoadBalancer(LoadBalancerContext.java:468) ~[ribbon-loadbalancer-2.2.0.jar:2.2.0] at com.netflix.loadbalancer.reactive.LoadBalancerCommand$1.call(LoadBalancerCommand.java:184) ~[ribbon-loadbalancer-2.2.0.jar:2.2.0] at com.netflix.loadbalancer.reactive.LoadBalancerCommand$1.call(LoadBalancerCommand.java:180) ~[ribbon-loadbalancer-2.2.0.jar:2.2.0] at rx.Observable.unsafeSubscribe(Observable.java:8460) ~[rxjava-1.1.5.jar:1.1.5] at rx.internal.operators.OnSubscribeConcatMap.call(OnSubscribeConcatMap.java:94) ~[rxjava-1.1.5.jar:1.1.5] at rx.internal.operators.OnSubscribeConcatMap.call(OnSubscribeConcatMap.java:42) ~[rxjava-1.1.5.jar:1.1.5]

Am I missing any configuration ?

Thank you for your help.

Advertisement

Answer

spencergibb pointed out the problem : no health check endpoint was deployed. Just adding spring-boot-actuator to the dependencies solved the issue.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement