apache camel route选择/过滤属性文件

时间:2016-04-07 03:11:54

标签: xml spring apache-camel

我正在配置一个看起来像这样的apache-camel路线:

<camelContext xmlns="http://camel.apache.org/schema/spring">
        <propertyPlaceholder id="properties" location="file:/../jboss/dependencies-fuse/archivo.properties"/>
        <route>
            <from uri="amqLocal:endpointA"/>
            <choice>
                <when>
                    <simple>{{property.var}} == 'F' </simple>
                    <to uri="amqLocal:endpointB"/>
                </when>
            </choice>
            <to uri="amqLocal:endpointC"/>
            <to uri="amqLocal:endpointD"/>   
        </route> 
</camelContext>

假设属性文件定义良好,我正在寻找一种方法,只有当名为property.var的属性等于&#39; F&时,我的路由器才能将消息传递给名为amqLocal:endpointB的端点。 #39 ;. 然后路由器应该继续向端点amqLocal:endpointC和amqLocal:endpointD抛出相同的消息。

我不知道它是否像我说的那样有效。也许我应该使用<filter>组件,但它总是抛出以下异常:

org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[JmsMessage[JmsMessageID: ID:emi-pc-38668-1459998422949-1:2:1:1:1]]
  at org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1635)[org.apache.camel:camel-core:2.15.1.redhat-621084 com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4.2]
  at org.apache.camel.builder.SimpleBuilder.createPredicate(SimpleBuilder.java:93)[org.apache.camel:camel-core:2.15.1.redhat-621084 com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4.2]
  at org.apache.camel.builder.SimpleBuilder.matches(SimpleBuilder.java:74)[org.apache.camel:camel-core:2.15.1.redhat-621084 com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4.2]
  at org.apache.camel.processor.ChoiceProcessor.process(ChoiceProcessor.java:92)[org.apache.camel:camel-core:2.15.1.redhat-621084 com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4.2]
  at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)[org.apache.camel:camel-core:2.15.1.redhat-621084 com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4.2]
  at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:448)[org.apache.camel:camel-core:2.15.1.redhat-621084 com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashma

有人可以帮忙吗?还有另一种好办法吗?

1 个答案:

答案 0 :(得分:0)

使用{{var}}而不是{{ }}是属性占位符语法:http://camel.apache.org/using-propertyplaceholder.html

如果您想使用简单语言引用属性占位符,则需要使用${ }语法,并使用properties-location函数:http://camel.apache.org/simple

那就是${properties-location:var}。使用此时,将在运行时为每条消息解析占位符。前者在Camel启动期间解决了一次。