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

相關問題