24

I would like to use Feign without client-side loadbalancer Ribbon because I don't want to run Eureka, which would need to be distributed and highly available. Instead internal ELBs with internal DNS names managed by Route53 will do just fine.

Providing plain URLs to @FeignClient always results in no loadbalancer found for .., so I tried preventing Feign from using Ribbon:

Spring Cloud Netflix comes with FeignRibbonClient, which is used if ILoadBalancer from ribbon-loadbalancer is present. However, if this dependency is excluded FeignConfiguration is broken:

Bean creation exception on FactoryBean type check: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'apiVersionClient': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: feign.codec.Decoder org.springframework.cloud.netflix.feign.FeignConfiguration.decoder; nested exception is java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy

Ideas welcome :-)

Konrad Hosemann
  • 251
  • 1
  • 2
  • 5
  • Why don't you want `ribbon-loadbalancer`? – spencergibb Dec 24 '14 at 22:01
  • I just added some context to the question: It's about Eureka. – Konrad Hosemann Dec 25 '14 at 18:22
  • Ribbon does not depend on Eureka. You just have to tell the load balancer where the remote servers are individually (e.g. create a `@RibbonClient` configuration and set the `ServerList` up as a `@Bean`). Which isn't to say that there might not be a bug in Spring Cloud preventing you from doing that easily. – Dave Syer Dec 26 '14 at 10:06
  • New docs: http://projects.spring.io/spring-cloud/spring-cloud.html#spring-cloud-feign-without-eureka – Dave Syer Dec 26 '14 at 15:20
  • Ok, I didn't try that. But my point is that I don't want to configure lists of servers, I just want to use a plain URL, as I would do using `RestTemplate`. – Konrad Hosemann Dec 26 '14 at 15:32
  • Isn't a plain URL just a list with one element? If you have a feature request, then put it in github, please. – Dave Syer Dec 26 '14 at 16:50

2 Answers2

28

If you want to use a plain URL use:

@FeignClient(value = "http://example.com", loadbalance = false)

With the Brixton release train you would use:

@FeignClient(url = "http://example.com", name = "example")
Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140
spencergibb
  • 24,471
  • 6
  • 69
  • 75
  • 1
    Where does the URL go then? – Dave Syer Dec 27 '14 at 08:34
  • 1
    Updated answer, it goes in `value` – spencergibb Dec 27 '14 at 17:25
  • 3
    @spencergibb `loadbalance` does not seem to be available in `@FeignClient` any more (Spring Boot 1.3.5, Brixton SR1 release). Any alternatives? – demaniak Jun 30 '16 at 10:41
  • @demaniak If you don't want to loadbalance you use `@FeignClient(url="http://example.com", name="example")` – spencergibb Jun 30 '16 at 14:19
  • 4
    Thanks @spencergibb. I also figured out I can disable ribbon with `ribbon.eureka.enabled=false` – demaniak Jul 01 '16 at 09:32
  • if eureka isn't on the classpath, that would disable it as well. – spencergibb Jul 06 '16 at 02:35
  • 2
    Greenwich release don't have attribute 'loadbalance'? – Maxi Wu May 20 '19 at 06:39
  • @spencergibb How do I disable the ribbon loadbalancer if I am building the url dynamically and passing URI object to feign client method call? I don't want to include the `url` attribute in the `@FeignClient` ? More details at https://stackoverflow.com/questions/61001300/java-spring-feign-errors-out-with-load-balancer-does-not-have-available-server – Pepria Apr 03 '20 at 01:40
5

Somewhat late, but after looking into this if you provide your own Client Bean the LoadBalancerFeignClient wont get built and used, and the Feign open tracing autoconfig will still work.

@Bean
public Client feignClient() {
    return new Client.Default(null, null);
}
Lovis
  • 9,513
  • 5
  • 31
  • 47
Jason
  • 526
  • 7
  • 9