【问题标题】:Spring Cloud config feign fallback(CircuitBreaker) ruleSpring Cloud config feign fallback(CircuitBreaker) 规则
【发布时间】:2017-07-28 18:12:12
【问题描述】:

现在我在 hystrix 中使用 feign,结果发现,当 fallback 方法在 5 秒内调用 20 次时,Circuit 将变为 Open 状态。我怎样才能改变这个规则。例如,当fallback方法在5s内调用50次时,让Circuit状态变为open,或者通过fallback回调率。 这是我的主要 java 代码。

ConsumerApplication.java

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
@EnableCircuitBreaker
@RibbonClients({@RibbonClient(name = "cloud-provider", configuration = CloudProviderConfiguration.class)})
public class ConsumerApplication {
    public static void main(String[] args) {
        SpringApplication.run(ConsumerApplication.class, args);
    }
}

UserFeignClient.java

@FeignClient(name = "cloud-provider", fallback = UserFeignClient.HystrixClientFallback.class)
public interface UserFeignClient {
    @RequestMapping("/{id}")
    BaseResponse findByIdFeign(@RequestParam("id") Long id);

    @RequestMapping("/add")
    BaseResponse addUserFeign(UserVo userVo);

    @Component
    class HystrixClientFallback implements UserFeignClient {
        private static final Logger LOGGER = LoggerFactory.getLogger(HystrixClientFallback.class);

        @Override
        public BaseResponse findByIdFeign(@RequestParam("id") Long id) {
            BaseResponse response = new BaseResponse();
            response.setMessage("disable!!!!");
            return response;
        }

        @Override
        public BaseResponse addUserFeign(UserVo userVo) {
            BaseResponse response = new BaseResponse();
            response.setMessage("disable");
            return response;
        }
    }
}

【问题讨论】:

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


    【解决方案1】:

    这里描述了配置参数https://github.com/Netflix/Hystrix/wiki/Configuration

    hystrix.command.default.circuitBreaker.sleepWindowInMilliseconds 更改您看到的 5 秒窗口。

    hystrix.command.default.circuitBreaker.requestVolumeThreshold 默认为 20 个请求。

    【讨论】:

    • @spencergibb 这些属性适用于所有 feign hystrix 客户端,对吧?如果我想单独更改特定 feign 客户端的 hystrix 属性怎么办?
    • @codingsplash 来这里找那个。
    猜你喜欢
    • 2017-08-22
    • 2019-02-11
    • 1970-01-01
    • 2017-07-19
    • 2016-02-18
    • 1970-01-01
    • 2021-02-03
    • 2015-08-24
    • 2017-07-23
    相关资源
    最近更新 更多