paulwong

          My Links

          Blog Stats

          常用鏈接

          留言簿(66)

          隨筆分類(1388)

          隨筆檔案(1146)

          文章分類(7)

          文章檔案(10)

          相冊(cè)

          收藏夾(2)

          AI

          Develop

          E-BOOK

          Other

          養(yǎng)生

          微服務(wù)

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          60天內(nèi)閱讀排行

          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發(fā)生在各種thread里時(shí),如何將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 閱讀(243) 評(píng)論(0)  編輯  收藏 所屬分類: SPRINGSPRING INTERGRATION

          主站蜘蛛池模板: 泰州市| 达拉特旗| 浏阳市| 五莲县| 南漳县| 上杭县| 梅河口市| 固原市| 土默特左旗| 高青县| 平谷区| 罗源县| 台州市| 洛南县| 无极县| 金秀| 象山县| 兴城市| 拉孜县| 怀集县| 中山市| 五莲县| 成安县| 嘉黎县| 德化县| 环江| 龙州县| 阜城县| 宕昌县| 漳州市| 香港 | 河北省| 梨树县| 曲水县| 安庆市| 长武县| 于田县| 崇明县| 南漳县| 上思县| 嘉定区|