简体   繁体   English

Apache Camel:setProperty和Groovy

[英]Apache Camel: setProperty and Groovy

I have the following Camel route: 我有以下骆驼路线:

<route id="myroute">
    <from uri="timer://runOnce?repeatCount=1&amp;delay=10" />

    <!-- Set a new property on the exchange. -->
    <to uri="bean:propSetter?method=setProp" />

    <to uri="direct:fizz" />
</route>

My PropSetter bean: 我的PropSetter bean:

public class PropSetter {
    // Add new "buzz" ArrayList<Long> to the exchange.
    public void setProp(Exchange exchange) {
        exchange.setProperty("buzz", new ArrayList<Long>());
    }
}

I would like to rewrite this without a Java bean and instead use Camel's <setProperty/> element. 我想不用Java Bean来重写它,而是使用Camel的<setProperty/>元素。 The only thing I can think of is to use the built-in Groovy expression: 我唯一能想到的就是使用内置的Groovy表达式:

<route id="myroute">
    <from uri="timer://runOnce?repeatCount=1&amp;delay=10" />

    <!-- Set a new property on the exchange. -->
    <setProperty propertyName="buzz">
        <groovy>new ArrayList&lt;Long&gt;();</groovy>
    </setProperty>

    <to uri="direct:fizz" />
</route>

But this does not seem to work. 但这似乎不起作用。 So how can I use XML to set a new ArrayList<Long> on the exchange called buzz ? 那么,如何在调用buzz的交换中使用XML来设置新的ArrayList<Long>呢?

Define a list using Spring's util namespace as : 使用Spring的util命名空间将列表定义为:

<util:list id="myList" value-type="java.lang.String">
</util:list>

Then using the simple language you can access the bean and set in an exchange property 然后,您可以使用简单的语言访问Bean并在exchange属性中进行设置

<camel:setProperty propertyName="buzz">
  <camel:simple>${bean:myList}</camel:simple>
</camel:setProperty>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM