【问题标题】:Split and Aggregate in Apache CamelApache Camel 中的拆分和聚合
【发布时间】:2017-11-01 22:10:52
【问题描述】:

我想拆分交换消息正文(它是 MyCustomClass 对象的列表),处理它们(一个接一个),然后它们将所有交换聚合在一起。拆分是可以的,一个一个的处理也可以,但是我不知道如何聚合它们。

from("mysource")
    .unmarshal(new ListJacksonDataFormat(MyClass.class))
    .split().body()
    .process(new Processor() {
        @Override
        public void process(Exchange exchange) throws Exception {
            // process MyClass item
            exchange.getIn().setBody(processedItem);
        }
    })
    .to("destinationForProcessedItem")
    .aggregate(new GroupedExchangeAggregationStrategy()) <== Seems like problem is here
    .process(new Processor() {
            // handle result of aggregation
    })

我不需要复杂的聚合,只需收集拆分的 Exchange 列表并在最终处理器中处理它们。

【问题讨论】:

    标签: apache-camel eip


    【解决方案1】:

    使用拆分器中的内置聚合器,查看组合消息处理器 EIP 模式:https://camel.apache.org/components/latest/eips/composed-message-processor.html#_sample

    【讨论】:

      【解决方案2】:

      这样写

               .aggregate(new AggregationStrategy() {
                      @Override
                      public Exchange aggregate(Exchange exchange, Exchange exchange1) {
                          //logic for aggregation using exchnage and exchange1
                      }
                  })
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-03-26
        • 1970-01-01
        • 1970-01-01
        • 2018-09-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多