2

to(uri)実行時に指定できるCamel ルートを構成したいと思います。

私は次のことを試しました:

public class Foo extends RouteBuilder {
    @Override
    public void configure() {
        // the URI can point to different hosts
        from("direct:start").to(${someUri}");
    }
}

その後

ProducerTemplate pt = camelContext.createProducerTemplate();
pt.requestBodyAndHeader("direct:start", "someUri", "http://example.com");

ただし、上記は機能しません (Camel はデフォルトのエンドポイントがないことを訴えます)。

これについて最善の方法は何ですか?

4

3 に答える 3

4

この質問はすでに回答されていますが、他の誰かがまだそれを行う方法を疑問に思っている場合に備えて、あなたが探しているものを達成するためのこの他のオプションを共有したいと思いました:

「toD」と呼ばれる Camel 2.16 以降の新しいメソッドがあります。これは基本的に「動的 to」を意味します。公式リファレンス ドキュメントはこちらです

from("direct:start")
  .toD("${someUri}");

この場合、 toD メソッドはSimple 言語を使用して引数を解決します。つまり、言語がサポートする任意のプロパティを使用できます。

同じトピックについて、この他の StackOverflow answer もご覧ください。

于 2016-11-17T15:18:36.090 に答える
3

参照用に次のリンクを参照してください。

http://camel.apache.org/how-do-i-use-dynamic-uri-in-to.html

http://camel.apache.org/recipient-list.html

例については、この単体テストを参照してください

https://svn.apache.org/repos/asf/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipientListTest.java

于 2012-07-05T15:28:10.053 に答える
0

前に「$」を付けずに中括弧を使用しただけです。これが私がしたことです:

{headers.reQueueName} instead of ${headers.reQueueName} for the uri and it worked : 
  <to id="requeue" uri="jmsamq:queue:{headers.reQueueName}"/> here is my implementation    :    


<route id="_throttleRoute">
            <from id="throttleRouteStarter" uri="direct:throttleRouteService"/>
            <log id="_Step_5" message="Camel throttle Route Started"/>
            <log id="_Step_5_1" message="Camel throttle Route is ${headers.next}"/>
            <to id="restThrottleCall" uri="restlet:http://host:port/path"/>
            <process id="throttleRouteProcess" ref="throttleServiceProcessor"/>
            <choice id="_choice2">`enter code here`
                <when id="_when3">
                    <simple>${headers.next} == 'requeue'</simple>   
                    <to id="requeue" uri="jmsamq:queue:{headers.reQueueName}"/>
                    <log id="_Step_wait1" message="ReQueue sending to ${headers.reQueueName}"/>
                </when>
                <when id="_when4">
                    <simple>${headers.next} == 'process'</simple>
                    <log id="_logNext" message="Invoking Next Work Unit ${headers.next}"/>
                    <process id="jBPMRouteProcess" ref="jBPMRouteProcessor"/>
                </when>
                <otherwise id="_otherwise2">
                    <log id="_log5" loggingLevel="WARN" message="Next for orderId: ${headers.orderid} not found"/>
                </otherwise>
            </choice>
        </route>
于 2017-08-15T20:30:05.887 に答える