paulwong

          SPRING INTEGRATION RETRY

          當使用httpOutBoundGateway時,有時會碰到網絡抖動問題而出現連接異常,這時應該有個重試機制,如隔多少秒重試,重試多少次后放棄等。
          默認是重試3次,每次重試間隔是20秒。

          @SpringBootApplication
          public class SpringIntegrationDslHttpRetryApplication {

              @SuppressWarnings("unchecked")
              public static void main(String[] args) {
                  ConfigurableApplicationContext applicationContext =
                          SpringApplication.run(SpringIntegrationDslHttpRetryApplication.class, args);
                  Function<Object, Object> function = applicationContext.getBean(Function.class);
                  function.apply("foo");
              }

              @Bean
              public IntegrationFlow httpRetryFlow() {
                  return IntegrationFlows.from(Function.class)
                          .handle(Http.outboundGateway("http://localhost:11111")
                                          .httpMethod(HttpMethod.GET)
                                          .expectedResponseType(String.class),
                                  e -> e.advice(retryAdvice()))
                          .get();
              }

              @Bean
              public RequestHandlerRetryAdvice retryAdvice() {
                  return new RequestHandlerRetryAdvice();
              }

          }

          #打印日志
          logging.level.org.springframework.retry=debug

          Reference:
          https://docs.spring.io/spring-integration/reference/html/handler-advice.html#retry-advice
          https://stackoverflow.com/questions/49784360/configure-error-handling-and-retry-for-http-outboundgateway-spring-dsl
          https://stackoverflow.com/questions/50262862/requesthandlerretryadvice-with-httprequestexecutingmessagehandler-not-working
          https://stackoverflow.com/questions/63689856/spring-integration-http-outbound-gateway-retry-based-on-reply-content
          https://blog.csdn.net/cunfen8879/article/details/112552420


          posted on 2021-08-23 13:01 paulwong 閱讀(254) 評論(0)  編輯  收藏 所屬分類: SPRING INTERGRATION

          主站蜘蛛池模板: 常州市| 南涧| 河东区| 大渡口区| 贵溪市| 临湘市| 英山县| 通许县| 深水埗区| 遂宁市| 乡城县| 宜昌市| 吴桥县| 兴仁县| 通城县| 永仁县| 清新县| 张家界市| 宁都县| 新宁县| 沅陵县| 根河市| 哈尔滨市| 年辖:市辖区| 商水县| 汶川县| 盈江县| 固始县| 双柏县| 边坝县| 梓潼县| 新宁县| 鹤岗市| 海门市| 吴忠市| 曲沃县| 页游| 双桥区| 安福县| 新绛县| 桂平市|