2012-07-05 66 views
1

我想配置一個駱駝路線,其中to(uri)可以在運行時指定。動態的(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"); 

然而上述不起作用(駱駝抱怨沒有一個默認的端點)。

這是什麼最好的方法呢?

+0

我已經回答了以下問題同樣的問題 http://stackoverflow.com/questions/15071934/camel-http-endpoint-forming-url-dynamically/21327170# 21327170 – vashishth 2014-01-24 07:55:10

回答

2
+0

我看到'recipientList()'在郵件列表中提到,但沒有太多運氣讓它工作。你能提供一個ProducerTemplate方面的例子嗎? – armandino 2012-07-05 20:15:18

+0

我添加了單元測試參考...應該讓你去 – 2012-07-05 21:24:32

+0

真棒。謝謝!完美工作。 – armandino 2012-07-06 10:35:01

1

雖然這個問題已經回答了,我想分享這個其他選項來實現你要找的東西,以防其他人仍然想知道如何去做:

有一個新的方法,因爲駱駝2.16叫「toD」,基本上意味着一個「動態的」。 Here is the official reference documentation

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

在這種情況下,TOD方法解決使用Simple language至極意味着您可以使用該語言支持任何財產的說法。

你也可以看看關於同一主題的this other StackOverflow answer

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>