【发布时间】:2018-05-09 22:19:32
【问题描述】:
我有以下配置文件。
@Configuration
@PropertySource({ "application.properties" })
@EnableIntegration
@IntegrationComponentScan
@EnableRetry
public class IntegrationBeanConfiguration {
@Bean
public SimpleRetryPolicy retryPolicy(){
SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy();
retryPolicy.setMaxAttempts(5);
return retryPolicy;
}
@Bean
public FixedBackOffPolicy fixedBackOffPolicy(){
FixedBackOffPolicy p = new FixedBackOffPolicy();
p.setBackOffPeriod(1000);
return p;
}
@Bean
public RequestHandlerRetryAdvice retryAdvice(SimpleRetryPolicy retryPolicy, FixedBackOffPolicy fixedBackOffPolicy){
RequestHandlerRetryAdvice retryAdvice = new RequestHandlerRetryAdvice();
RetryTemplate retryTemplate = new RetryTemplate();
retryTemplate.setBackOffPolicy(fixedBackOffPolicy);
retryAdvice.setRetryTemplate(retryTemplate);
return retryAdvice;
}
@Bean
@ServiceActivator(inputChannel="rtpRequestPostOperationRequestChannel")
public MessageHandler httResponseMessageHandler(MessageChannel rtpRequestPostOperationResponseChannel, HeaderMapper<HttpHeaders> headerMapper, RequestHandlerRetryAdvice retryAdvice) {
List<Advice> list = new ArrayList<>();
list.add(retryAdvice);
HttpRequestExecutingMessageHandler handler = new HttpRequestExecutingMessageHandler("https://myhost:8080/rtp/request");
handler.setHttpMethod(HttpMethod.POST);
handler.setHeaderMapper(headerMapper);
handler.setOutputChannel(rtpRequestPostOperationResponseChannel);
handler.setExpectedResponseType(RtpResponse.class);
handler.setAdviceChain(list);
return handler;
}
}
据我了解,如果我向不存在的 URL(如
)发出请求,则会触发重试https://myhost:8080/rtp/request123
但是重试没有发生。如果我的理解不正确或配置有问题,请指教。
谢谢
【问题讨论】:
-
您没有将
retryPolicy注入到模板中;但这只是意味着它将使用默认的 3 次尝试。 “不发生”是什么意思?重试通常是静默的。我建议您打开 DEBUG 日志记录以查看重试行为。 -
谢谢加里。现在我可以看到正在重试。
标签: spring-integration spring-retry