4

In my spring boot application I use multiple feign clients (@FeignClient("hello-service")). In the case of many of them, I need a mechanism of circuit breaker, so I have following line to the configuration.

feign.hystrix.enabled=true

However I'don't know how I can configure specific feign client not to use Hystrix. Is it possible? Has anyone managed to configure the spring applications in this way?

xiliann
  • 41
  • 2
  • You'd need to follow https://cloud.spring.io/spring-cloud-static/Greenwich.RELEASE/single/spring-cloud.html#spring-cloud-feign-overriding-defaults, and create a bean of `DefaultTargeter`. If you haven't figured it out soon, ping me and I'll find time to write up an answer. – spencergibb Mar 19 '19 at 19:32

2 Answers2

4

You can create you own configuration with disabled hystrix functionality, and use it for necessary clients.

public class FeignClientConfiguration {
@Bean
@Scope("prototype")
public Feign.Builder feignBuilder() {
    return Feign.builder();
}
}

See details in paragraph 7.4

Community
  • 1
  • 1
2

I'd like to extend Roman's answer as I didn't get how to use it at the beginning.

As he mentioned you need to have a configuration class like this

public class MyFeignConfiguration {

    @Bean
    @Scope("prototype")
    public Feign.Builder feignBuilder() {
        return Feign.builder();
    }
}

And you need to include this configuration class to your @FeignClient, like this

@FeignClient(name = "name", url = "http://example.com", configuration = MyFeignConfiguration .class)
public interface MyApi {
    //...
}

With this configuration this client will be built without being wrapped with Hystrix

Vitalii
  • 10,091
  • 18
  • 83
  • 151
  • This approach did not work for me. Adding the new @Bean disables my Hystrix behavior across all Feign clients. Even for the ones that don't use the new configuration class. Details here https://stackoverflow.com/questions/62669138/disable-hystrix-for-a-single-feign-client – Vinod Kumar Rai Jul 07 '20 at 02:35
  • It should work if the MyFeignConfiguration class has now @ Configuration annotation. From the offcial Feign docs: FooConfiguration does not need to be annotated with @ Configuration. However, if it is, then take care to exclude it from any @ ComponentScan that would otherwise include this configuration as it will become the default source for feign.Decoder, feign.Encoder, feign.Contract, etc., when specified. This can be avoided by putting it in a separate, non-overlapping package from any @ ComponentScan or @ SpringBootApplication, or it can be explicitly excluded in @ ComponentScan. – tonyfarney Nov 12 '21 at 19:39