paulwong

          SPRING INTEGRATION SCATTERGATHER

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

          對應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

          主站蜘蛛池模板: 新晃| 黄陵县| 襄樊市| 荆州市| 怀化市| 临城县| 云南省| 平邑县| 噶尔县| 历史| 桑植县| 章丘市| 昭觉县| 思南县| 疏附县| 阜康市| 五华县| 望江县| 红桥区| 陵水| 咸丰县| 修武县| 兰坪| 于田县| 习水县| 玉屏| 遵义县| 辽中县| 郸城县| 杭锦旗| 林州市| 民丰县| 兴和县| 梅河口市| 麻阳| 长治市| 龙井市| 南乐县| 电白县| 平度市| 舒城县|