Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Cloud config feign fallback(CircuitBreaker) rule

Now I use feign with hystrix, it turns out that Circuit will turn to Open status when fallback method invoke 20 times in 5s. How can I change this rule. For example, let the Circuit status turn to open when fallback method invoke 50 times in 5s, or by fallback callback rate. Here is my main java code.

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;
        }
    }
}
like image 678
Gabriel.ge Avatar asked Dec 18 '25 23:12

Gabriel.ge


1 Answers

The configuration parameters are described here https://github.com/Netflix/Hystrix/wiki/Configuration

hystrix.command.default.circuitBreaker.sleepWindowInMilliseconds changes the 5 second window you are seeing.

hystrix.command.default.circuitBreaker.requestVolumeThreshold defaults to 20 requests.

like image 75
spencergibb Avatar answered Dec 20 '25 18:12

spencergibb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!