首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Spring Cloud配置伪装回退(CircuitBreaker)规则

Spring Cloud配置伪装回退(CircuitBreaker)规则
EN

Stack Overflow用户
提问于 2017-03-08 16:57:24
回答 1查看 3.4K关注 0票数 3

现在我将feign与hystrix一起使用,结果是在5秒内回退方法调用20次时,电路将变为打开状态。如何更改此规则。例如,当回退方法在5秒内调用50次或回退回调速率时,电路状态变为open。下面是我的主要java代码。

ConsumerApplication.java

代码语言:javascript
运行
复制
@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

代码语言:javascript
运行
复制
@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;
        }
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-08 23:34:14

配置参数在此处https://github.com/Netflix/Hystrix/wiki/Configuration中描述

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

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

票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42666887

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档