Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable hystrix in one of multiple feign clients

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?

like image 330
xiliann Avatar asked Oct 25 '25 21:10

xiliann


2 Answers

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

like image 163
Roman Shtepa Avatar answered Oct 28 '25 21:10

Roman Shtepa


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

like image 45
Vitalii Avatar answered Oct 28 '25 21:10

Vitalii



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!