3

现在我使用feign与hystrix,事实证明,当回退方法在5秒内调用20次时,电路将变成打开状态。我怎样才能改变这个规则。例如,当回退方法在5秒内调用50次时,或回退回调速率时,让Circuit状态变为打开状态。 这是我的主要Java代码。Spring Cloud config feign fallback(CircuitBreaker)规则

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

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

hystrix.command.default.circuitBreaker.sleepWindowInMilliseconds改变你看到5第二窗口。

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

+0

谢谢!有用。 –

+0

@spencergibb这些属性适用于所有feign hystrix客户端吗?如果我想单独更改特定假客户的hystrix属性,该怎么办? – codingsplash

相关问题