【问题标题】:Spring Cloud: How to configure Hystrix in @FeignClientSpring Cloud:如何在@FeignClient 中配置Hystrix
【发布时间】:2016-12-12 13:57:13
【问题描述】:

我有以下服务:

@FeignClient(name = "person", fallback = FeignHystrixFallback.class)
public interface PersonService {

    @RequestMapping(value = "/find", method = RequestMethod.GET)
    Person findPerson(@RequestParam("name") String name);
}

如何更改默认超时时间和线程池大小?

【问题讨论】:

  • 嗨,feignclient 中没有定义 hystrix。 FeignClient 只是一个调用真实 enpoint 的接口。在控制器、组件中定义 hystrix ......
  • @duardito 如果是这样,为什么@FeignClientfallback= 属性有效?
  • fallback 是 histrix 的属性,而不是 hystrix 本身。 Fallback 是一个属性,请从文档中阅读:cloud.spring.io/spring-cloud-netflix/spring-cloud-netflix.htmlHystrix 支持回退的概念:当电路打开或出现错误时执行的默认代码路径。

标签: spring-cloud spring-cloud-netflix spring-cloud-feign


【解决方案1】:

还有其他人遇到了这个问题并发布了问题并得到了答案。最相关的是这篇文章:

Feign builder timeouts not working

如果您想管理 Feign 的配置,您可能需要查看 Feign 文档,查看 @FeignClient 注释的“配置”属性。

【讨论】:

    【解决方案2】:

    为此接口设置自定义配置

    @FeignClient(name="person", configuration = FeignConfig.class)
    

    并进行配置

    public class FeignConfig {
        public static final int FIVE_SECONDS = 5000;
    
        @Bean
        public Request.Options options() {
            return new Request.Options(FIVE_SECONDS, FIVE_SECONDS);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2016-01-10
      • 2016-03-31
      • 2016-06-18
      • 2019-07-30
      • 2016-05-21
      • 2018-09-20
      • 2015-05-31
      • 2018-07-21
      • 2020-05-30
      相关资源
      最近更新 更多