2014-07-08 56 views
1

我試着去訪問從會話變量設置成其它的流程的價值如何在騾子上使用其他流量的變量值?

代碼:

<flow name="test" doc:name="test" > 
    <http:inbound-endpoint exchange-pattern="request-response" address="http://localhost:8081/services/autocomplete" connector-ref="" transformer-refs="transform" doc:name="HTTP"> 
    </http:inbound-endpoint> 

    <set-variable variableName="req" value="#[message.inboundProperties['http.query.string']]" doc:name="Variable"/> 

    <set-session-variable variableName="message" value="test" doc:name="Set Message ID"/> 

    <http:outbound-endpoint host="teste.local" path="newlocation/autocomplete?#[groovy:return req.toString();]" port="8080" user="login" password="1234" exchange-pattern="request-response" doc:name="HTTP"> 
    </http:outbound-endpoint> 
</flow> 

和其他流動試圖打印:

<flow name="test2" doc:name="test2" > 
    <http:inbound-endpoint exchange-pattern="request-response" address="http://localhost:8081/services/autocomplete2" connector-ref="" transformer-refs="transform" doc:name="HTTP"> 
    </http:inbound-endpoint> 

    <set-variable variableName="req" value="#[message.inboundProperties['http.query.string']]" doc:name="Variable"/> 

    <logger message="#[sessionVars.message]" level="INFO" doc:name="Logger"/> 

    <http:outbound-endpoint host="teste.local" path="newlocation/autocomplete?#[groovy:return req.toString();]" port="8080" user="login" password="1234" exchange-pattern="request-response" doc:name="HTTP"> 
    </http:outbound-endpoint> 
</flow> 

但有一個錯誤saing有即使當我第一次嘗試訪問第一個url時,它也沒有設置到該流中的變量,所以我將它們更改爲第二個地方,以便創建會話。

- > mule version 3.4

回答

2

會話變量需要從一個流傳遞到另一個流。他們在事件中被序列化和反序列化。您將其設置在第一個流程中並調用/自動完成,但讀取它的流程正在偵聽/ autocomplete2。

在/ autocomplete之後,您不能單擊/ autocomplete2,並期望會話變量在那裏,因爲它在不同的事件上設置。如果您正在尋找存儲狀態之間的單獨流調用看看騾子對象存儲模塊

http://mulesoft.github.io/mule-module-objectstore/mule/objectstore-config.html

和Info上騾子對象存儲在這裏:

http://www.mulesoft.org/documentation/display/current/Mule+Object+Stores

一些示例配置,在這裏:

https://github.com/mulesoft/mule-module-objectstore/blob/master/src/test/resources/mule-config.xml

+0

嗨感謝您的反饋,這可能會回答我的問題,我會看看,試試,你有什麼樣的代碼,我可以基地開展地雷? –

+0

已更新答案,並鏈接到示例配置。注意你需要通過Maven等添加objectstore模塊。 –

+0

那麼我不能找到objectStore的模式...所以它一直給我一個錯誤,現在mulesoft只是不提供它...任何線索我在哪裏可以找到它? –

0

你的流量將是類似如下: -

<flow name="test" doc:name="test" > 
    <http:inbound-endpoint exchange-pattern="request-response" address="http://localhost:8081/services/autocomplete" doc:name="HTTP"> 
    </http:inbound-endpoint> 

    <set-variable variableName="req" value="#[message.inboundProperties['http.query.string']]" doc:name="Variable"/> 

    <set-session-variable variableName="message" value="test" doc:name="Set Message ID"/> 
     <logger message="Done #[sessionVars.message]" level="INFO" doc:name="Logger"/> 
     <http:outbound-endpoint exchange-pattern="request-response" method="POST" address="http://localhost:8081/services/autocomplete2" doc:name="HTTP"/> 
</flow> 

<flow name="test2" doc:name="test2" > 
    <http:inbound-endpoint exchange-pattern="request-response" address="http://localhost:8081/services/autocomplete2" doc:name="HTTP"> 
    </http:inbound-endpoint> 

    <set-variable variableName="req" value="#[message.inboundProperties['http.query.string']]" doc:name="Variable"/> 

    <logger message="#[sessionVars.message] #[sessionVars['message']] " level="INFO" doc:name="Logger"/> 


</flow>