我想对某些服务的API调用使用spring-retrials。这是我当前的代码:
@Retryable(value = {RuntimeException.class}, maxAttempts = 4, backoff = @Backoff(random = true, multiplier = 2, value = 30000))
public void requestSomeService(RequestData request) {
status = updateStatus(request, "REQUESTED");
Call<BaseResponse> transaction = serviceApi.addTransaction(request);
try {
Response<BaseResponse> execute = transaction.execute();
if (execute.isSuccessful()) {
updateTxStatus(request, "SUCCESS");
return;
}
else{
throw new RuntimeException();
}
} catch (Exception e) {
retryAddingTransaction(request);
}
throw new RuntimeException(e);
}
所有重试完成后,我想将交易状态更新为失败。我知道这可以在带有@Recover批注的函数中完成。
@Recover
public void updateTransactionFailedStatus(RequestData request){
updateTxStatus(request,"FAILED");
}
我不确定这是否是正确的方法,因为该API被多次(无限次)重试。也有人可以检查恢复功能如何工作,因为我也需要在其中传递requestData。