Java Camel中的动态到(URI)

Java Camel中的动态到(URI),java,integration,apache-camel,Java,Integration,Apache Camel,我想配置一个驼峰路由,其中可以在运行时指定到(uri) 我尝试了以下方法: public class Foo extends RouteBuilder { @Override public void configure() { // the URI can point to different hosts from("direct:start").to(${someUri}"); } } 然后 ProducerTemplate pt =

我想配置一个驼峰路由,其中可以在运行时指定
到(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抱怨没有默认端点)


最好的方法是什么?

请参阅以下链接:

有关示例,请参见此单元测试


虽然这个问题已经得到了回答,但我想与大家分享另一个选择,以实现您的目标,以防其他人仍然想知道如何实现:

自从Camel 2.16以来,出现了一种称为“toD”的新方法,其基本意思是“动态到”

在本例中,toD方法使用wich解析参数,这意味着您可以使用该语言支持的任何属性


你也可以看看,关于这个话题。

我只是简单地使用了大括号,前面没有“$”符号。以下是我所做的:

{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>
{headers.reQueueName}而不是uri的${headers.reQueueName},并且它起作用了:
以下是我的实现:
`在这里输入代码`
${headers.next}=='requeue'
${headers.next}==“进程”

我看到了邮件列表中提到的
recipientList()
,但没有太多的运气让它发挥作用。你能举一个例子来说明产品和模板方面的情况吗?太棒了。谢谢我在下面的问题中回答了同样的问题
{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>