2016-11-18 60 views
0

我在路由1中設置駱駝交換的屬性。我試圖在分離器內更新第二條路由。但在分離器的第二次迭代中,我獲得了我在路由1中設置的原始值,而不是新的更新值。下面是我努力的樣本..無法更新駝峯交換屬性

<route handleFault="true" streamCache="true" id="route1"> 
<from uri="cxfrs://bean://test?synchronous=true"/> 
     <bean ref="testBean" method="setMyProperty"/>// setting initial value for property 
     <to uri="direct:directCall"/> 
</route> 

<route handleFault="true" streamCache="true" id="route2"> 
    <from uri="direct:directcall"/> 
    <log message="Inside Second call..."/> 
    <split> 
    <jsonpath>some Json path</jsonpath> 
     <bean ref="formatConvertor" method ="convertLHMToJSON(${body})"/> 

    <split> 
     <jsonpath>some json path</jsonpath> 
    <bean ref="PropertySetter" method ="setProperty"/> //I am setting new value in this method 
    </split> 
    </split> 

豆內部:爲什麼不更新

public void setMyProperty(Exchange exchange) { 
      exchange.setProperty("testProp", "hello"); 
     } 

    public void setProperty(Exchange exchange) { 
      sysout(exchange.getProperty("testProp").toString())//this always prints "hello" 
      String x=exchange.getProperty("testProp")+some other value;// in all iterations of split I am getting 'hello' as the value of the property instead of new value 
      exchange.setProperty("testProp", x); 
      sysout(exchange.getProperty("testProp").toString())// this line prints the new value 
     } 

的財產?即使我嘗試設置標題。相同的結果。謝謝。

+0

爲什麼使用bean設置交換屬性?除非顯示的邏輯更多,否則可以執行.setProperty(「propertyName」,「propertyValue」);然後,您可以在分割中使用相同的代碼來更新屬性。 –

+0

其實,在設置屬性之前,我在bean中有很多轉換。再次在拆分我需要編寫業務邏輯之前我更新屬性。 – Jay

+0

從粘貼的代碼處理這個代碼有點難,爲什麼它不起作用,我之前已經更新了split中的交換屬性,並且工作正常。我認爲如果你用一個簡單的例子進行測試會更好。將SplitIndex放入交換屬性中並記錄該值。看到你可以在每次拆分過程中看到該屬性。 –

回答

2

您必須使用拆分聚合模式,並在從舊交換到新交換的拆分每次迭代期間複製屬性值,因爲每次發生拆分迭代時都會從源消息創建新交換(僅限於攜帶屬性&在分割之前設置的標頭) recover headers value after split apache camel

+0

謝謝sagar。拯救了我的一天。 – Jay