簡體   English   中英

Apache Camel:setProperty和Groovy

[英]Apache Camel: setProperty and Groovy

我有以下駱駝路線:

<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>

我的PropSetter bean:

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

我想不用Java Bean來重寫它,而是使用Camel的<setProperty/>元素。 我唯一能想到的就是使用內置的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>

但這似乎不起作用。 那么,如何在調用buzz的交換中使用XML來設置新的ArrayList<Long>呢?

使用Spring的util命名空間將列表定義為:

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

然后,您可以使用簡單的語言訪問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