Я использую Spring Retry, создав повторный ритмрат следующим образом:
import com.example.MyRetryProperties;
import com.example.SomeRetryableException;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.retry.annotation.EnableRetry;
import org.springframework.retry.support.RetryTemplate;
@Configuration
@EnableRetry
@RequiredArgsConstructor
public class RetryConfiguration {
private final MyRetryProperties retryProperties;
@Bean
public RetryTemplate retryTemplate() {
return RetryTemplate.builder()
.exponentialBackoff(
retryProperties.getInitialInterval(), // 500ms
retryProperties.getMultiplier(), // 2.0
retryProperties.getMaxInterval(), // 2000ms
false)
.withTimeout(retryProperties.getTimeout())
.retryOn(MyRetryableException.class)
.traversingCauses()
.build();
}
}
Если повторная попытка находится в процессе, я знаю, что я могу получить доступ к текущему количеству повторных попыток, используя retrycontext#getretrycount . Возможно ли каким -то образом получить доступ к текущему значению интервала без расчета его на основе количества повторных попыток (например, также из контекста)? < /P>
import org.springframework.retry.RetryCallback;
import org.springframework.retry.RetryContext;
import org.springframework.retry.RetryListener;
public class MyRetryListener implements RetryListener {
@Override
public void onError(RetryContext context, RetryCallback callback, Throwable throwable) {
int retryCount = context.getRetryCount();
System.out.println("Current retryCount: " + retryCount); // e.g. 3
int currentRetryInterval = // how?
System.out.println("Current retry interval: " + currentRetryInterval); // e.g. 2000ms for the third retry
}
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... rval-value
Как получить доступ к текущему значению интервала повторной попытки? ⇐ JAVA
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение