[英]Dynamic to(URI) in Camel
我想配置一個駱駝路線,可以在運行時指定to(uri)
。
我嘗試了以下方法:
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 2.16稱為“ toD”,因此有了一種新方法,基本上意味着“動態”。 這是官方參考文檔 。
from("direct:start")
.toD("${someUri}");
在這種情況下,toD方法使用簡單語言來解析參數,這意味着您可以使用該語言支持的任何屬性。
您也可以查看關於同一主題的另一個StackOverflow答案 。
我只是使用花括號而不在其前面加上“ $”。 這是我所做的:
{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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.