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

          主站蜘蛛池模板: 天台县| 岳池县| 澄迈县| 建德市| 微山县| 西安市| 陆川县| 灵石县| 青冈县| 榆中县| 厦门市| 罗源县| 常德市| 巴东县| 关岭| 延长县| 贵德县| 韩城市| 博客| 盐边县| 焦作市| 化德县| 高雄市| 梓潼县| 苏州市| 车致| 南阳市| 紫云| 龙川县| 娱乐| 西平县| 汉中市| 安义县| 师宗县| 隆尧县| 五河县| 寿光市| 泽库县| 房山区| 长治市| 建德市|