【问题标题】:How to use dynamic values in URI endpoints in apache camel XML configuration如何在 Apache Camel XML 配置中使用 URI 端点中的动态值
【发布时间】:2017-01-19 03:13:07
【问题描述】:

我正在使用 apache camel 在端点之间创建路由,通过在一个端口上运行在 Tomcat 上的一个 URI(API 网关),我正在映射到在不同域和端口上运行在 Tomcat 上的另一个 URI。

<bean id="hostnameVerifier" class="org.apache.http.conn.ssl.AllowAllHostnameVerifier" />
...
<camel:sslContextParameters id="ssl">
    <camel:keyManagers keyPassword="password">
        <camel:keyStore ... />
    </camel:keyManagers>
    <camel:trustManagers>
        <camel:keyStore ... />
    </camel:trustManagers>
</camel:sslContextParameters>
    ....

<rest path="/MyService" consumes="application/json" produces="application/json">

    <post uri="/login">
        <description>Authenticate User</description>
        <route streamCache="true">
            <to
                uri="https4://domain-b:9000/Auth/user/login?bridgeEndpoint=true&amp;sslContextParametersRef=ssl&amp;x509HostnameVerifier=hostnameVerifier" />
        </route>
    </post>
    ...
</rest>

现在,就我的 to 端点中的 domain-b 进行硬编码,一切正常。当我必须从某个配置文件的输入中动态填充该值时,就会出现问题。

这就是我试图达到同样效果的方式 -

<bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent">
    <property name="location" value="classpath:${LOCATION_PATH}propsfile.properties"/>
</bean>

属性键的名称是“域”,现在在我的端点定义中我写的是 -

<to
    uri="https4://${properties.domain}:9000/Auth/user/login?bridgeEndpoint=true&amp;sslContextParametersRef=ssl&amp;x509HostnameVerifier=hostnameVerifier" />

基本上在加载名为 properties 的 bean 中的属性后,我尝试将 domain-b 替换为 ${properties.domain} 或 #{properties.domain},但似乎不起作用。

如果有人可以建议,仅在基于 XML 的配置中,我如何从属性文件中读取 URL 域,那将是非常棒的。

-AJ

【问题讨论】:

  • 你试过uri="https4://{{properties.domain}}:9000 吗?内部骆驼路线元素属性可以这样使用。
  • 让我检查并更新。谢谢
  • 这样不行,还有其他建议吗?

标签: spring apache-camel


【解决方案1】:

你必须使用属性占位符来实现你想要的动态uri。

例如:

<camelContext ...>
   <propertyPlaceholder id="properties" location="YOUR_PROPERTY_FILE_LOCATION"/>
</camelContext>

然后试试

<to uri="https4://{{properties.domain}}:9000/.......>

注意:当你使用spring bean“PropertiesComponent”配置你的属性文件时,你必须在你的camel route中使用camel Property组件来实现动态值加载。

【讨论】:

    【解决方案2】:

    自骆驼 2.16 以来

    我们可以使用

    .from("file://path")
    .toD("file://folder/${file:onlyname}")
    

    我们可以使用文件

    【讨论】:

      猜你喜欢
      • 2014-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-16
      • 2016-04-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多