【问题标题】:Dynamic to(URI) in CamelCamel中的动态到(URI)
【发布时间】:2012-07-05 21:45:34
【问题描述】:

我想配置一个 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 抱怨没有默认端点)。

最好的方法是什么?

【问题讨论】:

标签: java integration apache-camel


【解决方案1】:

虽然已经回答了这个问题,但我想分享这个其他选项来实现您正在寻找的东西,以防其他人仍然想知道如何做到这一点:

自 Camel 2.16 以来有一种称为“toD”的新方法,基本上意味着“动态到”。 Here is the official reference documentation.

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

在这种情况下,toD 方法使用 Simple language 解析参数,这意味着您可以使用该语言支持的任何属性。

您也可以查看this other StackOverflow answer,关于同一主题。

【讨论】:

    【解决方案2】:

    【讨论】:

    • 我在邮件列表中看到了recipientList(),但没有太多运气让它发挥作用。您能否举例说明 ProducerTemplate 方面的外观?
    • 太棒了。谢谢!完美运行。
    【解决方案3】:

    我只是使用了没有'$' 的花括号。这是我所做的:

    {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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多