2

同じラクダのコンテキストで 2 つの開始点を使用するラクダのプロトタイプに取り組んでいます。

最初のルートは、アプリケーションの「構成」に使用されるメッセージを消費します。メッセージは configService Bean を介して構成リポジトリにロードされます。

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

2 番目のルートは、受信者リストの eip パターンを実装し、同じ構成リポジトリから動的に読み取られる多数の受信者に異なる種類の入力メッセージを配信します。

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

    // ...

ここで発生する問題は、それらを同期する方法です。そのため、最初のルートが新しいデータを処理している場合、2 番目のルートは「待機」します。

私は 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-configroute-configroute-sourceconfig

于 2014-06-20T15:20:40.353 に答える
1

2 番目のルートをアクティブにする最初のルートに「完了時」http://camel.apache.org/oncompletion.htmlを配置することもできます。

于 2013-08-06T07:39:03.333 に答える