【问题标题】:RetryListenerSupport handlers executed on all @Retryables在所有 @Retryables 上执行的 RetryListenerSupport 处理程序
【发布时间】:2021-07-02 07:58:08
【问题描述】:
我查看了文档,看起来(并且很直观)您必须在 @Retryable 注释侦听器的参数中注册 RetryListenerSupport。
但由于某种原因,RetryListenerSupport 会在项目中的所有 @Retryables 上执行,而不会将其添加到任何侦听器参数中 - 这是预期的行为吗?
如果是,听众的论点是什么?
【问题讨论】:
标签:
spring
listener
spring-retry
【解决方案1】:
抱歉,回答晚了,但我遇到了完全相同的问题。
我认为注释已更新,并且侦听器字段已删除,因为它未出现在当前文档中。
我为我的项目实现了一个新的拦截器,为了记录重试,我实现了一个 RetryListener,它注册在拦截器内部使用的新 RetryTemplate 中。
举个例子总比长解释好,它看起来像这样:
@Configuration
public class MyRetryInterceptor{
@Bean
public RetryOperationsInterceptor retryInterceptorCustom() {
UniformRandomBackOffPolicy backOffPolicy = new BackOffPolicy(); //Configure it
RetryPolicy retryPolicyCustom = new RetryPolicy(); //Configure it
RetryTemplate template = RetryTemplate.builder()
.customBackoff(backOffPolicy)
.customPolicy(retryPolicyCustom )
.withListener(new MyRetryListener())
.build();
RetryOperationsInterceptor interceptor = new RetryOperationsInterceptor();
interceptor.setRetryOperations(template);
return interceptor;
}
}
然后你可以像这样在@Retryable 注解中使用它:
@Retryable(interceptor = "retryInterceptorCustom")
我知道这根本不完美,所以使用它需要您自担风险。