【问题标题】:camel http endpoint forming url dynamically骆驼http端点动态形成url
【发布时间】:2013-02-10 21:21:11
【问题描述】:

我正在尝试使用的人

{
from("direct:a").to (someUrl).processor(new Processor(){

   @Override
   public void process(Exchange arg0) throws Exception
   {
      // do something
   }

});


where someUrl is of the type http://xyz.com/{id}?test=<value1>&test1=<value2>
}

并且这个 url 会随着路由的每个请求而改变。

我已经尝试过了。将参数作为标题传递并尝试使用 header("test") 和使用 ${in.header.test} 在路由中访问两者似乎都不起作用。

任何建议都会很有帮助。

【问题讨论】:

    标签: http url dynamic apache-camel endpoint


    【解决方案1】:

    查看有关 Camel 中动态到端点的常见问题解答:https://camel.apache.org/manual/latest/faq/how-to-use-a-dynamic-uri-in-to.html

    【讨论】:

    • 再次阅读常见问题解答!您不能在 TO 中使用动态值,而应使用 RECIPIENT LIST。
    • 我知道这个问题已经得到解答,但它会是使用骆驼的正确方法吗(它是一种反模式)吗?因为eip在这里的用法不一样:enterpriseintegrationpatterns.com/RecipientList.html
    • 这当然不是反模式。 EIP 将消息路由到动态的收件人列表。这就是 Camel 实现的作用。收件人列表可以是 1..n 个收件人。
    • 感谢@claus。有没有其他方法可以进行具有路径参数的远程(不是我们公开的)RESTful 调用。我想只有其他人想到的是设置 HTTP_URI 标头,它将覆盖到端点的值。就理想的骆驼使用而言,哪一个更好。
    • 有没有办法让
    【解决方案2】:

    从骆驼 2.16 开始,你可以做这样的事情 -

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

    参考:http://camel.apache.org/message-endpoint.html

    【讨论】:

    • 调用动态 https url 的任何线索。例如:toD("https://${header.foo}/bar")
    【解决方案3】:

    你可以使用骆驼属性占位符

    http://camel.apache.org/using-propertyplaceholder.html

    <camelContext trace="false" xmlns="http://camel.apache.org/schema/spring">
        <propertyPlaceholder location="config/AuditJMSConfig.properties" id="properties" />
        <route id="crudRoute">
            <from uri="activeMQ:queue:{{speedwing.activemq.auditqueue}}/>
        </route>                                                                                    where speedwing.activemq.auditqueue is the property name defined in the peroperties file.
    

    你可以对&lt;to uri="" also使用相同的

    【讨论】:

    • 嗯,这是“半动态的” - 当骆驼被初始化时,属性被使用,并且从此时 具有恒定值。但问题是关于每个请求的动态端点..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-05
    • 1970-01-01
    • 1970-01-01
    • 2014-06-20
    • 1970-01-01
    相关资源
    最近更新 更多