RequestHandlerRetryAdvice 与 HttpRequestExecutingMessageHandler 不工作
RequestHandlerRetryAdvice with HttpRequestExecutingMessageHandler not working
我有以下配置文件。
@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
但是没有重试。如果我的理解有误或者配置有问题请指教
谢谢
在 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;
}
}
我有以下配置文件。
@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
但是没有重试。如果我的理解有误或者配置有问题请指教
谢谢
在 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;
}
}