2

我正在研究一个骆驼原型,它在同一个骆驼上下文中使用两个起点。

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

    // read configuration files
    from("file:data/config?noop=true&include=.*.xml")
        .startupOrder(1)
        .to("bean:configService?method=loadConfiguration")
        .log("Configuration loaded");   

第二个路由实现了一个接收者列表 eip 模式,将不同类型的输入消息传递给多个接收者,这些接收者从同一个配置存储库中动态读取:

    // process some source files (using configuration)       
    from("file:data/source?noop=true")
        .startupOrder(2)
        .unmarshal()
        .to("setupProcessor") // set "recipients" header
        .recipientList(header("recipients"))

    // ...

现在出现的问题是如何同步它们,因此如果第一个路由正在处理新数据,则第二个路由“等待”。

我是 Apache Camel 的新手,对如何解决这样的问题非常迷茫,任何建议都将不胜感激。

4

3 回答 3

3

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

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。如果在目录中找到新文件,则会重新route-config启动。route-sourceconfig

于 2014-06-20T15:20:40.353 回答
1

您还可以在激活第二个路由的第一个路由中放置一个“完成时” http://camel.apache.org/oncompletion.html

于 2013-08-06T07:39:03.333 回答
0

Apache camel File 将为正在处理的文件创建一个锁。如果有锁,则此文件上的任何其他文件进程都不会合并(除非您设置了 consumer.exclusiveReadLock=false)

来源 :

http://camel.apache.org/file.html => URI 选项 => consumer.exclusiveReadLock

于 2013-04-04T14:01:50.233 回答