How to disable hystrix in one of multiple feign clients

江枫思渺然 提交于 2021-01-28 02:50:37

问题


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?


回答1:


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




回答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



来源:https://stackoverflow.com/questions/55200113/how-to-disable-hystrix-in-one-of-multiple-feign-clients

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!