尽管使用其他返回类型 Spring 重试回退机制似乎工作正常,但是在调用返回类型为 void 的 API 时。Recover 方法根本没有被调用,我已经尝试了所有可能类型的方法参数并更改了回退方法的返回类型.... 有没有办法做到这一点?我不明白为什么@CircuitBReaker 注释没有参数来将后备方法名称作为值传递给它?
@CircuitBreaker(maxAttempts = 3, openTimeout = 8000, resetTimeout = 15000)
public Void callingXYZ(final Abc abc, final Cdf cdf) {
return retryTemplate.execute(context -> {
log.info("Retry count={} when calling ******", context.getRetryCount());
AbcServiceImpl.this.update*****Settings(OrgId.fromString(abc.getUUID(), cdf.getData());
return null;
});
}
//Recover method that should get invoked
@Recover
public Void fallbackUpdate*****(Throwable e, Abc abc) throws Throwable{
log.info("Inside fallback");
if (e instanceof ClientException) {
log.warn("Fallback method is called when trying to call ******** from ****** because of {}", e.getCause());
//Rollback in the db based on the method attributes
throw SpecificException.forTask(HttpStatus.SERVICE_UNAVAILABLE.value(),
Enum.NAME.getErrorCode(),
Enum.NAME.getMEssage(), true);
}
throw e;
}
我在我的代码中解决了这个问题,它与 spring-retry 项目无关。由于我对 AOP 的 Spring 实现缺乏了解,我无法找到问题的解决方案。由于 Spring 的方面应用于围绕 bean 的代理而不是实际类,因此如果从同一类/服务调用带有 @circuitbreaker 的方法将不起作用。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句