spring-cloud - Spring Cloud config feign fallback(CircuitBreaker) 规则

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

现在我在 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;
        }
    }
}

最佳答案

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

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

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

关于spring-cloud - Spring Cloud config feign fallback(CircuitBreaker) 规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42666887/

相关文章:

java - Spring Boot 微服务中的安全问题

java - 仅将 https 与 spring cloud 微服务实例一起使用

spring - javanica @HystrixCommand 和 spring @Cacheable 执行顺序

java-8 - Observable 发射器对 HystrixCommands 产生太大的压力

load-balancing - 具有WebClient的功能区负载平衡器与其余模板不同(未正确平衡)

spring-cloud - 从 zuul 过滤器发送重定向

java - 重启后 Config Server 的多个请求

spring-boot - 在 Spring-Boot 应用程序中使用 application.yaml 配置 hystrix 命令属性

kubernetes - Hystrix-dashboard 无法与 Kubernetes 上的 Kubeflix 配合使用

error-handling - @HystrixProperty无法解析为类型