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 閱讀(251) 評論(0)  編輯  收藏 所屬分類: SPRING INTERGRATION

          主站蜘蛛池模板: 普安县| 仪征市| 台安县| 年辖:市辖区| 桦川县| 屏东市| 安庆市| 湘阴县| 湘潭市| 桃园县| 玉环县| 文成县| 五大连池市| 普兰店市| 五常市| 时尚| 银川市| 攀枝花市| 垦利县| 霍山县| 石嘴山市| 施甸县| 都昌县| 青海省| 梁河县| 曲阜市| 民和| 福建省| 德钦县| 阿拉善盟| 镇雄县| 武强县| 余江县| 宁明县| 吴江市| 上杭县| 江阴市| 平阳县| 扶余县| 门头沟区| 东辽县|