英文:
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.
专注分享java语言的经验与见解,让所有开发者获益!
评论