Spring Cloud: How to use Feign without Ribbon
Solution 1
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")
Solution 2
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);
}
Related videos on Youtube
Konrad Hosemann
Updated on June 04, 2022Comments
-
Konrad Hosemann almost 2 years
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 inno loadbalancer found for ..
, so I tried preventing Feign from using Ribbon:Spring Cloud Netflix comes with
FeignRibbonClient
, which is used ifILoadBalancer
fromribbon-loadbalancer
is present. However, if this dependency is excludedFeignConfiguration
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 :-)
-
Dave Syer over 9 yearsWhere does the URL go then?
-
spencergibb over 9 yearsUpdated answer, it goes in
value
-
demaniak almost 8 years@spencergibb
loadbalance
does not seem to be available in@FeignClient
any more (Spring Boot 1.3.5, Brixton SR1 release). Any alternatives? -
spencergibb almost 8 years@demaniak If you don't want to loadbalance you use
@FeignClient(url="http://example.com", name="example")
-
demaniak almost 8 yearsThanks @spencergibb. I also figured out I can disable ribbon with
ribbon.eureka.enabled=false
-
spencergibb almost 8 yearsif eureka isn't on the classpath, that would disable it as well.
-
Maxi Wu almost 5 yearsGreenwich release don't have attribute 'loadbalance'?
-
Pepria about 4 years@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 stackoverflow.com/questions/61001300/…