You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Apache Camel并行拆分器执行行为异常及参数疑问

Apache Camel 3.11.3拆分器并行引发的路由执行顺序异常问题

我的Apache Camel路由出现了不符合预期的执行行为,路由代码如下:

from("sftp://...")
    .autoStartup(isReadyToStart())
    .routeId(model.getName())
    .filter().method(startTrigger)
        .bean(RouteHelperIn.class,"start")
        .bean(initialize)
        .bean(RouteHelperIn.class, "startChunk")
        .convertBodyTo(InputStream.class)
        .split().tokenize(newLine)
                         .streaming()
                         .stopOnException()
                         .executorServiceRef(splitterExecutorService)
            .filter().method(RouteHelperIn.class,"isContentRow") //Skip header rows using the removeFirstLines route parameter
                .unmarshal(jdf)
                .bean(mapper)
                .bean(RouteHelperIn.class, "generateAndUpdateLog")
                .bean(writeToDb)
            .end()
        .end()
        .bean(RouteHelperIn.class, "endChunk")
        .bean(postProcessing).to("direct://" + sub.getCopy())
        .bean(RouteHelperIn.class, "writeLastImportLog")
        .bean(RouteHelperIn.class, "end")
    .end()

场景复现

假设SFTP消费者读取到两个文件:

  • 当splitterExecutorService设为null时,拆分器无并行能力,两个文件对应的交换按顺序执行——第二个RouteHelperIn#start会在第一个RouteHelperIn#end执行完成后才启动,符合预期。
  • 当配置splitterExecutorService启用拆分器并行后,根据官方文档描述:

If enabled then processing each split messages occurs concurrently. Note the caller thread will still wait until all messages has been fully processed, before it continues. It’s only processing the sub messages from the splitter which happens concurrently.

但实际观察到的情况是:第二个RouteHelperIn#start在第一个RouteHelperIn#end执行前就启动了,且执行线程ID始终相同,完全不符合文档描述,这直接导致了严重bug。我原本预期仅拆分器内部的子消息处理是并行的,整体路由仍按顺序处理每个文件。

请问这是Apache Camel 3.11.3的版本bug,还是我对文档的理解存在偏差?

更新

我发现给SFTP消费者URI添加synchronous=true后,问题得到解决,但无法理解:为什么拆分器无并行时消费者是同步执行的,启用并行后就变成异步了?这和文档描述完全不符。

内容的提问来源于stack exchange,提问作者Simone

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 09:05:19