我Spring Boot 2中尝试使用Resilience4j。
当我在控制器类上实现时,是可以正常工作的,但当我在内部/服务方法中实现并尝试触发@CircuitBreaker时,它根本不起作用。
代码如下:
@CircuitBreaker(name =SOME_SERVICE,fallbackMethod = "getStubResponse")
public String getResponse(String xml) {
String result ;
HttpPost post = new HttpPost(some_url);
post.setHeader("Accept", "text/xml");
post.setHeader("Content-type", "text/xml");
HttpEntity entity = null;
try {
entity = new ByteArrayEntity(xml.getBytes("UTF-8"));
post.setEntity(entity);
} catch (UnsupportedEncodingException e) {
throw new SomeException("UnsupportedEncodingException occured in SomeCall "+e);
}
try (CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = httpClient.execute(post)) {
result = EntityUtils.toString(response.getEntity());
} catch (IOException io) {
log.logError("OhubCall", "getResponseError", io.getMessage());
throw new ArticlesException("IO Exception Occured in Call "+io);
}
return result;
}
@CircuitBreaker(name =SOME_SERVICE,fallbackMethod = "getStubResponse")
public String getResponse2(String xml) {
String some_url = "some_servlet_url"
WebClient client = WebClient.create();
return client
.post()
.uri(some_url)
.body(BodyInserters.fromValue(xml))
.exchange()
.flatMap(response -> response.bodyToMono(String.class))
.block();
}
当应用程序/服务类调用servlet时,我正在尝试实现@CircuitBreaker。我还尝试从相同的内部服务类实现@CircuitBreaker,并用另一个ResTemplate调用,它可以正常工作。因此,问题似乎出现在HttpClient和WebClient上。两者都没有触发@CircuitBreaker,有人碰到过这个问题吗?
没有回复内容