3

现在我在 hystrix 中使用 feign,结果发现,当 fallback 方法在 5s 内调用 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;
        }
    }
}
4

1 回答 1

8

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

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

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

于 2017-03-08T15:34:13.857 回答