Apache Camel和路由中的多线程。它不等待“choice”路由完成

huangapple 未分类评论46阅读模式
英文:

Apache Camel and multithreading in a route. It doesn't wait for a "choice" route to finish

问题

人们。
我有一个(我希望)对于Apache Camel专家来说很简单的问题。
我有以下的路由(为了显示错误位置,我对其进行了简化,除了我要解释的错误之外,路由工作得很好)

from(ROUTE_URI)
    .routeId(ROUTE_ID)
    .choice()
        .when(simple(FILE_EXISTS))
            .log(LoggingLevel.INFO, INFO_MESSAGE_6)
            .to(PROCESS_1_ZIP)
            .to(PROCESS_2_ZIP)
            .process(ex -> ex.getIn().setBody(ex.getIn().getHeaders().get(HEADER)))
        .otherwise()
            .log(LoggingLevel.INFO, FILE_DOES_NOT_EXIST)
            .to(CHANGE_ZIP)
            .to(PROCESS_2_ZIP)
            .setHeader(HEADER, simple("true"))
    .end()

    .choice()
        .when(simple(OPTION_6))
            .process(this::translateToWhateverCommandWeWant)
            .to(ROUTE_URI)
            .process(ex -> ex.getIn().setBody(ex.getIn().getHeaders().get(HEADER)))
    .end()
    .to(UPDATE_FILE)
    .choice()
        .when(simple(OPTION_7))
            .to(CREATE_ZIP)
    .end()
    .log(LoggingLevel.INFO, "Finished process with ID blabla");

这个路由工作得很好,但是有一个异常:我发现了一些奇怪的行为(对我来说是奇怪的,因为我是Camel的新手),我不太理解。
即使FILE_EXISTS选项尚未完成,UPDATE_FILE也会被执行。因此,有时候这个过程会失败,因为该过程所需的一些文件在步骤FILE_EXISTS中创建,而在此过程中这些文件是不可用的。
这是Camel的正常行为吗?
我原以为Camel会等待选择路径完成后再继续执行。
我没有使用多线程,也没有在不同的线程中执行步骤FILE_EXISTS
提前谢谢。

英文:

people.
I have an (I hope) easy question for experts in Apache Camel.
I have the following route (it's simplified to show where the error is, the route is working fine except for the error I'm explaining)

    from(ROUTE_URI)
        .routeId(ROUTE_ID)
        .choice()
            .when(simple(FILE_EXISTS))
                .log(LoggingLevel.INFO, INFO_MESSAGE_6)
                .to(PROCESS_1_ZIP)
                .to(PROCESS_2_ZIP)
                .process(ex -> ex.getIn().setBody(ex.getIn().getHeaders().get(HEADER)))
            .otherwise()
                .log(LoggingLevel.INFO, FILE_DOES_NOT_EXIST)
                .to(CHANGE_ZIP)
                .to(PROCESS_2_ZIP)
                .setHeader(HEADER, simple("true"))
        .end()

        .choice()
            .when(simple(OPTION_6))
                .process(this::translateToWhateverCommandWeWant)
                .to(ROUTE_URI)
                .process(ex -> ex.getIn().setBody(ex.getIn().getHeaders().get(HEADER)))
        .end()
        .to(UPDATE_FILE)
        .choice()
            .when(simple(OPTION_7))
                .to(CREATE_ZIP)
        .end()
        .log(LoggingLevel.INFO, "Finished process with ID blabla");

The route is working fine with this exception: I have checked some weird behaviour ( for me, I'm a newbie in Camel) which I don't understand.
UPDATE_FILE is executed even when FILE_EXISTS option has not yet finished. So, sometimes the process fails because some files needed for that process to work are not available because they are created in step FILE_EXISTS.
Is this the normal behaviour for Camel?.
I thought Camel waits for a choice path to finish before continuing the execution.
I'm not using multiple threads or executing the step FILE_EXISTS in a different thread.
Thanks in advance.

huangapple
  • 本文由 发表于 2020年4月5日 16:44:03
  • 转载请务必保留本文链接:https://java.coder-hub.com/61040052.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定