paulwong

          Error handling in spring integration - How to get all the errors thrown in multiple threads and send them to the error-channel

          在SPRING INTEGRATION中,如果exception發生在各種thread里時,如何將exception返回到指定的channel,之后再繞回到aggrator-channel中。

          @Bean
          public IntegrationFlow provisionUserFlow() {
          return
              IntegrationFlows.from("input.channel")
              .publishSubscribeChannel(Executors.newCachedThreadPool(),
                  s -> s.applySequence(true)
                      .subscribe(f -> f.enrichHeaders(e -> e.header(MessageHeaders.ERROR_CHANNEL, "errorChannel", true))
                          .handle(provisionerA, "provision")
                          .channel("aggregatorChannel")
                      )
                      .subscribe(f -> f.enrichHeaders(e -> e.header(MessageHeaders.ERROR_CHANNEL, "errorChannel", true))
                          .handle(provisionerB, "provision")
                          .channel("aggregatorChannel"))
                      )
                  .get();
          }

          @Bean
          public IntegrationFlow aggregateFlow() {
              return IntegrationFlows.from("aggregatorChannel")
                              .channel( aggregatorChannel)
                              .aggregate( a -> a.processor( collect, "aggregatingMethod"))
                              .get();
          }

          @Transformer( inputChannel = "errorChannel", outputChannel = "aggregatorChannel")
          public Message<?> errorChannelHandler(ErrorMessage errorMessage) throws RuntimeException {

              Message<?> failedMessage =  ((MessagingException) errorMessage.getPayload()).getFailedMessage();

              Exception exception = (Exception) errorMessage.getPayload();

              return  MessageBuilder.withPayload( exception.getMessage())
                                                 .copyHeadersIfAbsent( failedMessage.getHeaders() )
                                                 .build();
          }


          https://stackoverflow.com/q/46495127/11790720

          posted on 2020-10-15 19:21 paulwong 閱讀(242) 評論(0)  編輯  收藏 所屬分類: SPRINGSPRING INTERGRATION

          主站蜘蛛池模板: 神农架林区| 海兴县| 沛县| 兰西县| 曲松县| 苍山县| 宁南县| 西青区| 孝昌县| 县级市| 景宁| 邢台县| 阜南县| 寿宁县| 永新县| 莆田市| 昆山市| 隆化县| 文安县| 富平县| 黄冈市| 崇明县| 温泉县| 武隆县| 沙坪坝区| 滕州市| 民勤县| 凤台县| 沙田区| 贡嘎县| 安吉县| 张掖市| 金湖县| 岗巴县| 塘沽区| 梨树县| 项城市| 来宾市| 夏河县| 林芝县| 基隆市|