我有以下配置文件。
@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;
}
}
根据我的理解,如果我向
等不存在的网址发出请求,则会触发重试https://myhost:8080/rtp/request123
但重试不会发生。如果我的理解不正确或配置有问题,请告知。
由于
答案 0 :(得分:0)
在Gary的评论的帮助下。以下配置有效
@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);
retryTemplate.setRetryPolicy(retryPolicy)
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;
}
}