Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use @FeignClient without ribbon?

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

like image 707
fyrkov Avatar asked Mar 03 '23 12:03

fyrkov


1 Answers

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

like image 153
Joel Eze Avatar answered Mar 06 '23 01:03

Joel Eze