我想設置屬性isEven在Exchange.property,然後使用選擇當來評估它的路線。
該物業正在設置,但我總是得到,否則結果(NACK)無論什麼是EVE設置。駱駝交易所屬性不用簡單的XML在評估
這裏是我設置:
// Below is used for development
// If the property.isEven == true then an ACK will be returned from the Mock HRM
// If false then NACK
int lastDigit = Integer.parseInt(exchange.getExchangeId().substring(exchange.getExchangeId().length() - 1));
// check if lastDigit is odd or even
if ((lastDigit & 1) == 0)
{
exchange.setProperty("isEven", Boolean.TRUE);
System.out.println("\n\n\n********** Exchange Id lastDigit " + lastDigit + " isEven: " + exchange.getProperty("isEven") + " ***********");
}
else
{
exchange.setProperty("isEven", Boolean.FALSE);
System.out.println("\n\n\n********** Exchange Id lastDigit " + lastDigit + " isEven: " + exchange.getProperty("isEven") + " ***********");
}
中的println的節目,我設置ISEVEN我期望的那樣。 這裏是路線:
<!-- Used to ramdomly send Ack or Nack -->
<log message="isEven property is :: ${property[isEven]}" />
<camel:choice>
<camel:when>
<simple>"${property[isEven]}"</simple>
<transform>
<constant>ACK</constant>
</transform>
</camel:when>
<camel:otherwise>
<transform>
<constant>NACK</constant>
</transform>
</camel:otherwise>
</camel:choice>
日誌消息從未計算表達式$ {屬性[ISEVEN]} 這裏是輸出 日誌[ISEVEN屬性是:: $ {屬性[ISEVEN]}]
如果我更改簡單表達式來明確檢查是否真的我總是得到ACK無論屬性設置爲什麼。
<simple>"${property[isEven]} == true"</simple>
我已經搜索了網頁,但找不到很多使用簡單和Exchange屬性的示例。
任何人都可以看到我錯過了什麼?
感謝,
安德魯
彼得表明,他能做到這一點很容易我試過他的例子,我還沒有嘗試過2之後。這是一個。它不適合我。它生成了Hello :: NACK,無論isEven是true還是false:
<camel:choice>
<camel:when>
<simple>${property[isEven]} == "true"</simple>
<log message="HELLO :: ACK" />
<!-- <transform>
<constant>ACK</constant>
</transform> -->
</camel:when>
<camel:otherwise>
<log message="HELLO :: NACK" />
<!-- <transform>
<constant>NACK</constant>
</transform> -->
</camel:otherwise>
</camel:choice>
這是一件有趣的事情。它看起來像下面的日誌是說其空在最後像
********** Exchange Id lastDigit 2 isEven: true ***********
14/02/20 14:09:13 INFO interceptor.Tracer: >>> (toHRMRoute) bean://hl7handler?method=handleORM --> log[isEven property is :: ${property[isEven]}] <<< Pattern:InOut, Properties {CamelToEndpoint=bean://hl7handler?method=handleORM, CamelMessageHistory [DefaultMessageHistory[routeId=toHRMRoute, node=to3], DefaultMessage History[routeId=toHRMRoute, node=log1]], CamelCreatedTimestamp=Thu Feb 20 14:09:13 CST 2014}
14/02/20 14:09:13 INFO toHRMRoute: ** isEven property is :: **
我覺得彼得是,它必須是我有我的路線設置方式正確。
<endpoint id="hrmMockHL7Listener"
uri="netty:tcp://localhost:9200?sync=true" />
<!-- Sending data using postman to a rest server-->
<route id="pushRESTRoute">
<from uri="cxfrs://bean://pushRESTServer" />
<!-- this process is where we set isEven on the Exchange-->
<process ref="transformer"/>
<!-- Send it to a tcp listener at port 9200-->
<to ref="hrmMockHL7Listener" />
</route>
<!-- Changed routes does the Exchange keep properties? -->
<route id="toMRoute">
<from uri="hrmMockHL7Listener" />
<to uri="bean:hl7handler?method=handleORM" />
<!-- Used to ramdomly send Ack or Nack -->
<log message="isEven property is :: ${property[isEven]}">
// see the beginning of the question for choice code.
望着輸出似乎ISEVEN屬性被丟棄的路線之間:
14/02/21 09:37:26 INFO interceptor.Tracer: >>> (pushRESTRoute) ref:transformer --> tcp://localhost:9200 <<< Pattern:InOut, Properties {CamelMessageHistory=[DefaultMessageHistory[routeId=pushRESTRoute, node=process1], DefaultMessageHistory[routeId=pushRESTRoute, node=to1]], CamelCreatedTimestamp=Fri Feb 21 09:37:26 CST 2014, isEven=true}
見ISEVEN在結束了嗎?自帶接下來的示蹤劑沒有它
/02/21 09:37:26 INFO interceptor.Tracer: >>> (toMRoute) from(tcp://localhost:9200) --> bean://hl7handler?method=handleORM <<< Pattern:InOut, Properties:{CamellMessageHistory=[DefaultMessageHistory[routeId=toMRoute, node=to3]], CamelCreatedTimestamp=Fri Feb 21 09:37:26 CST 2014}
從交易所的javadoc
An Exchange is the message container holding the information during the entire routing of a Message received by a Consumer.
是否整個包括跨型動物路線?
你使用什麼版本的駱駝? –
我正在使用2.12.2 – KingAndrew