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

          主站蜘蛛池模板: 呈贡县| 鹤庆县| 和田县| 甘孜| 温宿县| 蓬莱市| 谢通门县| 南华县| 虞城县| 东乡族自治县| 安图县| 贵港市| 清镇市| 沁源县| 大丰市| 闵行区| 濉溪县| 巴林右旗| 潜江市| 乐安县| 亳州市| 溧阳市| 房产| 永济市| 隆尧县| 惠水县| 天水市| 西吉县| 湘潭县| 马尔康县| 建德市| 兰州市| 金山区| 新蔡县| 邯郸市| 临泉县| 四会市| 舟曲县| 河北区| 绥滨县| 滁州市|