Код: Выделить всё
@Retryable(retryFor = {TechnicalException.class})
public void createPropertyWithRetry(CustomData customData)
throws TechnicalException {
try {
List response =
clientApi.createCustomData(customData);
} catch (ApiException e) {
if (isTechnicalError(e)) {
throw new TechnicalException("Technical error");
}
}
}
@Retryable(retryFor = {TechnicalException.class})
public void updatePropertyWithRetry(CustomData customData)
throws TechnicalException {
try {
List response =
clientApi.updateCustomData(customData);
} catch (ApiException e) {
if (isTechnicalError(e)) {
throw new TechnicalException("Technical error");
}
}
}
Код: Выделить всё
@Recover
public void recoverFromTechnicalFailure(
TechnicalException ex,
CustomDataApi customDataApi,
CustomDataDetail customDataDetail,
String propertyCode) {
logErrorMessage(
log,
"Operation failed after {} retries for property {}",
maxRetryAttempts,
propertyCode,
ex);
metricsService.incrementRetriesExhausted();
throw new TechnicalException(
"Failed to process property " + propertyCode + " after all retries", ex);
}
Часть метода оркестратора, которая вызывает вышеуказанные методы
Код: Выделить всё
void makeApiCall(){
try {
apiService.createPropertyWithRetry(customDataApi);
} catch (ApiException apiException) {
if (doesPropertyExist(apiException)) { // checks and
apiService.updatePropertyWithRetry(customDataApi);
} else {
// handling / re-throwing other exceptions
}
}
}
Как правильно выбросить ApiException из моего повторяемого метода?
Поскольку он повторяет попытку только для технического исключения, если я выбрасываю ApiException из этих методов, приложение выдает исключение ниже:
Код: Выделить всё
org.springframework.retry.ExhaustedRetryException: Cannot locate recovery methodПодробнее здесь: https://stackoverflow.com/questions/797 ... -method-in
Мобильная версия