骆驼分割/聚合和合并List that contains List that contains List

问题描述 投票:0回答:1

鉴于与此类似的结构:

@Data
public class A {
    //..other fields..

    private List<B> bs;
}

@Data
public class B {
    //..other fields..

    private List<C> cs;
}

我必须处理A型的多步骤/路由列表。有些操作是在A级,其他人在其他层面像C.

我试图解决的问题是处理每一个C中给出的A,然后一些逻辑,事后有更新的模型工作。

我可以成功地分裂和聚集回list<C>但现在我卡住试图重建为B和C.给定输出

这是我目前所面对的:

from("direct:my-A-Item")
    .id("direct-a")
    .autoStartup(true)
    .split(ExpressionBuilder.beanExpression(new CSplitter(), "getBs"), new MyAggregationStrategy())
        .streaming()
        .split(ExpressionBuilder.beanExpression(new CSplitter(), "getCs"), new MyAggregationStrategy())
            .streaming()
            .bean(processor, "doStuff")//Working on a since C instance
        .end()
        .bean(processor, "test") //Here I get the worked List<C>
    .end()
    //.bean(processor, "thisProcessorNeedsA").end(); //TODO get the original A and the output List<C> so i can make further work on them

如何更新与C的新名单在B实例,然后做同样的更新?

public class CSplitter {

    public List<B> getBs(A a) {
        return a.getBs();
    }

    public List<C> getCs(B b) {
        return b.getCs();
    }
}

public class MyAggregationStrategy implements AggregationStrategy {

    @Override
    public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
        Object newBody = newExchange.getIn().getBody();
        ArrayList<Object> list = null;
        if (oldExchange == null) {
            list = new ArrayList<Object>();
            list.add(newBody);
            newExchange.getIn().setBody(list);
            return newExchange;
        } else {
            list = oldExchange.getIn().getBody(ArrayList.class);
            list.add(newBody);
            return oldExchange;
        }
    }
}

检查文档和在线资源,我找不到任何例子汇集来自前面的步骤还具有体...任何提示都是欢迎的。

spring-boot apache-camel dsl
1个回答
0
投票

我想捕捉身体A作为交换财产分割之前,那么这将是稍后提供。

from("direct:my-A-Item")
    .id("direct-a")
    .autoStartup(true)
    .setProperty("originalA", body())
    .split
      // etc.
    .end()
    .bean(processor, "myMethod(${property.originalA}, ${body})").end(); 
© www.soinside.com 2019 - 2024. All rights reserved.