2012-07-05 65 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>