我使用 Spring Boot2 starter ( https://resilience4j.readme.io/docs/getting-started-3 ) 在我的项目中实现了resilience4j。
我用 @CircuitBreaker 注释了一个方法,该方法使用 http 客户端来调用外部服务,并且断路器工作正常 - 包括其后备。
我想为其添加单元测试,但是当我运行尝试模拟回退的测试时,没有任何反应 - 抛出异常但不由断路器机制处理。
我找到了一些使用其指标的示例,但它对我来说没有用。
有什么想法吗?
这是我的客户的片段:
@CircuitBreaker(name = "MY_CICUIT_BREAKER", fallbackMethod = "fallback")
public ResponseEntity<String> search(String value) {
ResponseEntity<String> responseEntity = restTemplate.exchange(
searchURL,
HttpMethod.GET,
new HttpEntity(new HttpHeaders()),
String.class,
value);
}
public ResponseEntity<String> fallback(String value, ResourceAccessException ex) {
return "fallback executed";
}
Run Code Online (Sandbox Code Playgroud)