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

          主站蜘蛛池模板: 海盐县| 大洼县| 南投县| 滁州市| 略阳县| 剑河县| 荣成市| 乌鲁木齐市| 永吉县| 曲麻莱县| 晋州市| 乐亭县| 交城县| 肇源县| 天长市| 宣城市| 杨浦区| 菏泽市| 南乐县| 泾源县| 康平县| 霍邱县| 兰坪| 岗巴县| 儋州市| 鄂尔多斯市| 安吉县| 大安市| 米易县| 双峰县| 唐海县| 漠河县| 汕头市| 昌都县| 五大连池市| 鲜城| 鸡泽县| 库伦旗| 普宁市| 旬阳县| 九龙县|