Apache Camel 中拆分的并行处理线程

Parallel processing threads on split in Apache Camel

我正在尝试根据某种逻辑在路由中拆分传入交换。每个拆分部分都将连接到 bean 中的 ssh 服务器。

from("seda:compression")
    .routeId("Compressor")
    .split(beanExpression(new InstanceListParser(), "process"))
    .parallelProcessing()
        .to("bean:compressorClient?method=compress(${header.remoteHost},${header.dataCenter})")
    .end();

但似乎最多有 10 个进程正在并行 运行。

我添加了以下代码来增加线程池工厂的大小,但这没有帮助。

ThreadPoolProfile poolProfile = new ThreadPoolProfile("masterPoolProfile");
poolProfile.setMaxPoolSize(100);
poolProfile.setMaxQueueSize(100);
poolProfile.setPoolSize(50);
poolProfile.setKeepAliveTime(1L);
poolProfile.setTimeUnit(TimeUnit.MINUTES);

ThreadPoolFactory poolFactory = new DefaultThreadPoolFactory();
poolFactory.newThreadPool(poolProfile, Executors.defaultThreadFactory());

getContext().getExecutorServiceManager().setThreadPoolFactory(poolFactory);

您需要将拆分器配置为使用 masterPoolProfile 作为线程池或将 masterPoolProfile 配置为默认配置文件。后者意味着在 Camel 中使用 API 创建的所有线程池都将使用此配置文件作为基线。

在 Camel 文档中阅读更多相关信息:http://camel.apache.org/threading-model.html

这对我有用:

ThreadPoolProfile poolProfile = new ThreadPoolProfile("masterPoolProfile");
poolProfile.setMaxPoolSize(100);
poolProfile.setMaxQueueSize(100);
poolProfile.setPoolSize(50);
poolProfile.setKeepAliveTime(1L);
poolProfile.setTimeUnit(TimeUnit.MINUTES);
getContext().getExecutorServiceManager().setDefaultThreadPoolProfile(poolProfile)