Apache camel Camel:同一Camel上下文中并行路由之间的同步

Apache camel Camel:同一Camel上下文中并行路由之间的同步,apache-camel,Apache Camel,我正在开发一个camel原型,它在同一个camel上下文中使用两个起点 第一条路由使用用于“配置”应用程序的消息。消息通过configService bean加载到配置存储库中: //读取配置文件 from(“文件:data/config?noop=true&include=.*.xml”) .启动订单(1) .to(“bean:configService?方法=loadConfiguration”) .log(“已加载配置”); 第二条路由实现了收件人列表eip模式,将不同类型的输入消息传递

我正在开发一个camel原型,它在同一个camel上下文中使用两个起点

第一条路由使用用于“配置”应用程序的消息。消息通过configService bean加载到配置存储库中:

//读取配置文件
from(“文件:data/config?noop=true&include=.*.xml”)
.启动订单(1)
.to(“bean:configService?方法=loadConfiguration”)
.log(“已加载配置”);
第二条路由实现了收件人列表eip模式,将不同类型的输入消息传递给多个收件人,这些收件人从同一配置存储库中以友好方式读取:

//处理一些源文件(使用配置)
from(“文件:数据/源?noop=true”)
.启动订单(2)
.unmarshal()
.to(“setupProcessor”)//设置“收件人”标题
.收件人列表(标题(“收件人”))
// ...
现在出现的问题是如何同步它们,因此如果第一条路由正在处理新数据,那么第二条路由将“等待”


我是Apache Camel的新手,对于如何处理这样的问题非常迷茫,如果有任何建议,我将不胜感激。

Apache Camel文件将为正在处理的文件创建一个锁。如果存在锁,则此文件上的任何其他文件进程都不会共用(除非您将consumer.exclusiveredlock=false)

资料来源:


=>URI选项=>consumer.exclusiveReadLock

Apache camel文件将为正在处理的文件创建一个锁。如果存在锁,则此文件上的任何其他文件进程都不会共用(除非您将consumer.exclusiveredlock=false)

资料来源:


=>URI选项=>consumer.exclusiveReadLock

您还可以在激活第二条路由的第一条路由中放置“完成时”。

您还可以放置“完成时”在激活第二条路线的第一条路线中。

使用
聚合
并结合动态启动和停止路线的可能性:

from("file:data/config?noop=true&include=.*.xml")
    .id("route-config")
    .aggregate(constant(true), new MyAggregationStrategy()).completionSize(2).completionTimeout(2000)
    .process(new Processor() {
        @Override
        public void process(final Exchange exchange) throws Exception {
            exchange.getContext().startRoute("route-source");
        }
    });

from("file:data/source?noop=true&idempotent=false")
    .id("route-source")                              // the id is needed so that the route is found by the start and stop processors
    .autoStartup(false)                              // this route is only started at runtime
    .aggregate(constant(true), new MyAggregationStrategy()).completionSize(2).completionTimeout(2000)
    .setHeader("recipients", constant("direct:end")) // this would be done in a separate processor
    .recipientList(header("recipients"))
    .to("seda:shutdown");                            // shutdown asynchronously or the route would be waiting for pending exchanges

from("seda:shutdown")
    .process(new Processor() {
        @Override
        public void process(final Exchange exchange) throws Exception {
            exchange.getContext().stopRoute("route-source");
        }
    });

from("direct:end")
    .log("End");

这样,
route source
仅在
route config
完成时启动<如果在
config
目录中找到新文件,则会重新启动代码>路由配置,从而重新启动
路由源

使用
聚合
,并可动态启动和停止路由:

from("file:data/config?noop=true&include=.*.xml")
    .id("route-config")
    .aggregate(constant(true), new MyAggregationStrategy()).completionSize(2).completionTimeout(2000)
    .process(new Processor() {
        @Override
        public void process(final Exchange exchange) throws Exception {
            exchange.getContext().startRoute("route-source");
        }
    });

from("file:data/source?noop=true&idempotent=false")
    .id("route-source")                              // the id is needed so that the route is found by the start and stop processors
    .autoStartup(false)                              // this route is only started at runtime
    .aggregate(constant(true), new MyAggregationStrategy()).completionSize(2).completionTimeout(2000)
    .setHeader("recipients", constant("direct:end")) // this would be done in a separate processor
    .recipientList(header("recipients"))
    .to("seda:shutdown");                            // shutdown asynchronously or the route would be waiting for pending exchanges

from("seda:shutdown")
    .process(new Processor() {
        @Override
        public void process(final Exchange exchange) throws Exception {
            exchange.getContext().stopRoute("route-source");
        }
    });

from("direct:end")
    .log("End");

这样,
route source
仅在
route config
完成时启动<如果在
config
目录中找到新文件,则会重新启动代码>路由配置,从而重新启动
路由源

两条路由都使用来自不同输入文件夹的不同文件,如果我的问题不清楚,我很抱歉。我已经更新了。两个路由都使用来自不同输入文件夹的不同文件,如果我的问题不清楚,我很抱歉。我已经更新了。