paulwong

          My Links

          Blog Stats

          常用鏈接

          留言簿(67)

          隨筆分類(1392)

          隨筆檔案(1150)

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

          主站蜘蛛池模板: 冷水江市| 托克托县| 同心县| 乐业县| 巢湖市| 甘肃省| 绥化市| 阜平县| 宜黄县| 大方县| 衢州市| 黑龙江省| 成武县| 确山县| 古丈县| 宜都市| 铁力市| 上杭县| 江阴市| 车致| 米林县| 荃湾区| 万州区| 肇东市| 得荣县| 桐柏县| 中西区| 延津县| 基隆市| 长宁区| 越西县| 遵化市| 商丘市| 扶绥县| 金秀| 岢岚县| 磐安县| 泗洪县| 桐柏县| 从化市| 正阳县|