4
votes

I want to use @FeignClient(url=...) and make it go directly to the given url instead of picking up hosts from ribbon config.

I am aware that in spring-cloud feign comes together with ribbon and eureka by default.

According to this: https://cloud.spring.io/spring-cloud-netflix/multi/multi_spring-cloud-ribbon.html#spring-cloud-ribbon-without-eureka it is possible to disable eureka and provide a hardcoded list of hosts for ribbon, ex:

${serviceId}:
  ribbon:
    listOfServers: ${host}

And according to this: https://cloud.spring.io/spring-cloud-netflix/multi/multi_spring-cloud-feign.html it is possible to provide an explicit url for feign, ex:

@FeignClient(name = "${feign.name}", url = "${feign.url}")
public interface StoreClient {
    //..
}

So I'm a bit confused about what will FeignClient use after all: provided url or hosts from ribbon config?

I'd expect some prop to disable ribbon for feign as well because what's the point in load balancing if feign is given a single url?

Spring-cloud release train - Camden.SR2

1

1 Answers

7
votes

Yes you can use Feign without Ribbon, All you need to do is specify the base url in your Feign Java interface class.

And your interface signature should have the complete url endpoint.

An example is shown below.

@FeignClient(url = "http://someurl")
public interface MyInterface {

    @GetMapping("path/to/endpoint")
    MyObject get();

}

The sample code above shows how to send a GET request to http://someurl/path/to/endpoint