paulwong

          SPRING INTEGRATION SCATTERGATHER

          場景,餐廳:
          1. 食客下單,有飲品、食物、甜點
          2. 侍應(yīng)接單,傳送給廚房
          3. 廚房分三個子流程處理,即飲品、食物、甜點子流程
          4. 等待三個子流程處理完,合并成一份交付
          5. 如果廚房發(fā)現(xiàn)某食物欠缺,會通知侍應(yīng),展開錯誤處理,即通知食客更改食物,再交給廚房
          6. 侍應(yīng)將交付品傳送給食客
          有一個主流程、三個子流程和一個聚合流程,聚合流程會聚合三個子流程的產(chǎn)物,通知主流程,再往下走。
          并且主流程會感知子流程的錯誤,并會交給相應(yīng)錯誤處理流程處理,且將結(jié)果再交給聚合流程。

          對應(yīng)SPRING INTEGRATION 的SCATTERGATHER模式:
          @Bean
          public IntegrationFlow scatterGatherAndExecutorChannelSubFlow(TaskExecutor taskExecutor) {
              return f -> f
                      .scatterGather(
                              scatterer -> scatterer
                                      .applySequence(true)
                                      .recipientFlow(f1 -> f1.transform(p -> "Sub-flow#1"))
                                      .recipientFlow(f2 -> f2
                                              .channel(c -> c.executor(taskExecutor))
                                              .transform(p -> {
                                                  throw new RuntimeException("Sub-flow#2");
                                              })),
                              null,
                              s -> s.errorChannel("scatterGatherErrorChannel"));
          }

          @ServiceActivator(inputChannel = "scatterGatherErrorChannel")
          public Message<?> processAsyncScatterError(MessagingException payload) {
              return MessageBuilder.withPayload(payload.getCause().getCause())
                      .copyHeaders(payload.getFailedMessage().getHeaders())
                      .build();
          }

          https://github.com/adnanmamajiwala/spring-integration-sample/tree/master/dsl-scatter-gather/src/main/java/com/si/dsl/scattergather

          https://docs.spring.io/spring-integration/docs/5.1.x/reference/html/#scatter-gather

          posted on 2021-01-28 10:11 paulwong 閱讀(301) 評論(0)  編輯  收藏 所屬分類: SPRING INTERGRATION

          主站蜘蛛池模板: 历史| 婺源县| 牡丹江市| 富锦市| 呼玛县| 枝江市| 瓦房店市| 墨江| 武夷山市| 麻江县| 湘西| 搜索| 错那县| 榕江县| 琼海市| 会东县| 汕尾市| 三门峡市| 南昌县| 九江市| 榆社县| 安西县| 临高县| 商河县| 海淀区| 特克斯县| 忻城县| 建平县| 邛崃市| 闽清县| 同心县| 紫金县| 蓝田县| 乌兰浩特市| 明星| 石家庄市| 宜黄县| 当涂县| 东安县| 台北市| 福泉市|