Код: Выделить всё
@EnableRetry
@Import({GrpcClientRetryConfig.class})
@Retryable(interceptor = "grpcClientRetryInterceptor", label = "ProfileGrpcClient")
public class ProfileGrpcClient {
public RateLimitConfig getRateLimitConfig()
@AllArgsConstructor
публичный класс RateLimits {
частный конечный клиент ProfileGrpcClient;
// Некоторые вызывает метод client.getRateLimitConfig()
Перехватчик определен в GrpcClientRetryConfig
Код: Выделить всё
@EnableRetry
public class GrpcClientRetryConfig {
@Bean
public RetryOperationsInterceptor grpcClientRetryInterceptor() {
val template = new RetryTemplate();
val backOffPolicy = new ExponentialBackOffPolicy();
// Set the exponential backoff parameter
val interceptor = new RetryOperationsInterceptor();
template.setRetryPolicy(new SimpleRetryPolicy());
template.setBackOffPolicy(backOffPolicy);
template.setListeners(new GrpcClientRetryListener[] {new GrpcClientRetryListener()});
interceptor.setRetryOperations(template);
return interceptor;
}
}
Код: Выделить всё
@Slf4j
@Component
public class GrpcClientRetryListener extends MethodInvocationRetryListenerSupport {
@Override
public void onSuccess(
RetryContext context, RetryCallback callback, T result) {
if (callback instanceof MethodInvocationRetryCallback methodInvocationRetryCallback) {
log.info(
"Retry Succeeded: {}, Count: {}",
getMethodName(methodInvocationRetryCallback),
context.getRetryCount());
}
super.onSuccess(context, callback, result);
}
@Override
public void onError(
RetryContext context, RetryCallback callback, Throwable throwable) {
if (callback instanceof MethodInvocationRetryCallback methodInvocationRetryCallback) {
log.info(
"Retry Failing: {}, Count: {}",
getMethodName(methodInvocationRetryCallback),
context.getRetryCount());
}
super.onError(context, callback, throwable);
}
private String getMethodName(
MethodInvocationRetryCallback methodInvocationRetryCallback) {
return methodInvocationRetryCallback.getLabel();
}
}
Код: Выделить всё
Retry Failing: public com.abc.proto.v2.common.ratelimit.RateLimits com.abc.grpcclients.ProfileGrpcClient.getRateLimitConfig(), Count: 5
Подробнее здесь: https://stackoverflow.com/questions/782 ... s-level-in