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;
}
}
}
謝謝!有用。 –
@spencergibb這些屬性適用於所有feign hystrix客戶端嗎?如果我想單獨更改特定假客戶的hystrix屬性,該怎麼辦? – codingsplash