7
votes

I am aware that we can force FeignClient to use OkHttp instead of Ribbon by providing the url Ex. @FeignClient(url="serviceId", name="serviceId")

I want the OkHttpClient to be used even when just the name is provided. Ex. @FeignClient(name="serviceId")

As per the spring cloud documentation "if Ribbon is enabled it is a LoadBalancerFeignClient, otherwise the default feign client is used."

How can I disable ribbon so that the default feign client will be used.

2
ribbon is a loadbalancer, we don't use it's http client, so I'm a bit confused. You can you OkHttp with ribbon. Is that what you want?spencergibb
Netflix FeignClient by default looks for a loadbalancer. I want to use OkHttp without loadbalancer. I am able to achieve that by providing url and name attributes in the @feignClient annotation. But I would like to know if the same can be acheived just by providing the name attribute in @feignclient annotation.Vidhyashankar Madheswaraswamy
Using just the name will always use a load balancerspencergibb
So even if ribbon is not on the classpath, it will still look for a loadbalancer. right? and is it possible to override that behaviour by some workaround?Vidhyashankar Madheswaraswamy
If ribbon isn't on the class path, where the url come from?spencergibb

2 Answers

0
votes

I had the same question but my setup is a bit different and I did not get it working in my case (using spring-cloud-starter-openfeign with spring mvc style annotations).


FYI: I needed a custom client with an SSLSocketFactory and ended up just creating the bean for the client and keeping the url on @FeignClient

 @Bean
 public Client myClient() {
     return new Client.Default(getSSLSocketFactory(), new NoopHostnameVerifier());
 }

However, we do have projects using spring-cloud-starter-feign where the URL is not provided on the annotation. Not sure if the config below is complete (I did not set it up) but it might point you in the right direction...

dependencies

compile("org.springframework.cloud:spring-cloud-starter-feign") {
    exclude group: 'org.springframework.cloud', module: 'spring-cloud-starter-ribbon'
    exclude group: 'org.springframework.cloud', module: 'spring-cloud-starter-archaius'
}

config

@Configuration
@Import(FeignClientsConfiguration.class) // org.springframework.cloud.netflix.feign.FeignClientsConfiguration
public class MyConfig {

    @Value("${client.url}")
    private String url;    

    @Bean
    public MyClient myClient(final Decoder decoder, final Encoder encoder, final Client client) {
        return Feign.builder().client(client)
            .encoder(encoder)
            .decoder(decoder)
            .target(MyClient.class, url);
    }
}
0
votes

It has nothing to do with Ribbon.

Check this:

feign:
  httpclient:
    enabled: false

This will disable the spring cloud autoconfigured httpclient, and will search a @Bean named httpClient in the context. So provide the definition of @Bean in a @Configuration class and that's all.

Check class FeignAutoConfiguration in spring cloud feign.

https://cloud.spring.io/spring-cloud-netflix/multi/multi_spring-cloud-feign.html