【问题标题】:Starting camel route from XML DSL dynamically从 XML DSL 动态启动骆驼路由
【发布时间】:2018-02-17 14:58:59
【问题描述】:

我正在尝试根据属性文件中的布尔值有条件地启动 XML DSL 中的路由。但这有点行不通。我不确定这是否是正确的做法。任何帮助表示赞赏,谢谢:)

这是我的 blueprint.xml

<bean id="bridgePropertyPlaceholder" class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer">
    <property name="location" value="classpath:property.properties"/>
</bean>

<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">


    <route autoStartup="${isTrue}">
        <from uri="pipe:prs:P" />
        <choice>
            <when>
                <simple>${headers.headerName} == 'DR91'</simple>
                <process ref="reqType"></process>
                <to uri="direct-vm:pipeRequestDR91" />
            </when>
            <when>
                <simple>${headers.headerName} == 'DR93'</simple>
                <process ref="reqType"></process>
                <to uri="direct-vm:pipeRequestDR93" />
            </when>
        </choice>
    </route>

这是我的属性文件 - property.properties

isTrue=true

我得到的错误是:

org.apache.camel.RuntimeCamelException: 
org.apache.camel.FailedToCreateRouteException: Failed to create route 
route1: Route(route1)[[From[pipe:prs:P]] -> [Choice[[When[simple{${h... 
because of Error parsing [${isTrue}] as a Boolean.

【问题讨论】:

  • 您用blueprint-osgi 标记了您的问题,但您使用的是Spring BridgePropertyPlaceholderConfigurer。我认为您的标记错误或您使用了 BridgePropertyPlaceholderConfigurer。
  • 是的,我标记错了。谢谢

标签: xml spring apache-camel


【解决方案1】:

【讨论】:

    【解决方案2】:

    您应该使用 Camel 的属性占位符语法 {{xxx}},例如 do

     <route autoStartup="{{isTrue}}">
    

    【讨论】:

    • 谢谢克劳斯 :) 所以这有效,现在我遇到了其他问题。由于它启动了路由来检查它是否会在再次启动时工作,所以它触发了我的 bean 。我们可以避免吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-05
    • 2015-09-27
    • 1970-01-01
    • 2017-11-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多