Camel转向顺序过程

Camel转向顺序过程

我有两条路线:

1-从队列中读取并创建一个resultObject

2-等待直到在文件夹内创建特定文件,然后修改路由1中的resultObject。结果将在队列中发送。

连接这两条路线的最佳方法是什么?

目前,我有:

public class FirstRouteBuilder extends RouteBuilder {

    @Override
    public void configure() {
        from(myqueue)
            .process(exchange -> {
                // prepare ResultObject
                // add to camel context the second route that is initializated with resultObject
                SecondRouteBuilder secondRouteBuilder = new SecondRouteBuilder(resultObject);
                camelCtx.addRoutes(secondRouteBuilder);
                camelCtx.start();
            });
    }
}


public class SecondRouteBuilder extends RouteBuilder {

    public SecondRouteBuilder (ResultObject result){
        this.resultObject = result;
    }

    @Override
    public void configure() {
        from(waitingAFileFromDirectory)
            .process(exchange -> {
                // process the file using the resultObject
            })
            .to(resultQueue);
    }
}

最佳答案

通过pollEnrichloopDoWhile串联它们


pollEnrich获取文件
loopDoWhile控制文件获取行为


public class CombineRouteBuilder extends RouteBuilder {

    @Override
    public void configure() {
        from(myqueue)
            .process(exchange -> {
                // prepare ResultObject and save to exchange property
            })
            .loopDoWhile(simple(<boolean gate to control file obtain strategy>))
                .pollEnrich(AFileFromDirectory)    // get your file
                // maybe a process to control boolean gate of loopDoWhile
            .end() // end loop
            .process(exchange -> {
                // process the file using the resultObject from exchange property
            })
            .to(resultQueue);
    }
}

关于java - Apache Camel转向顺序过程,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58483766/

10-09 10:20