我试图从会话变量集中访问一个值到另一个流
代码:
<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>
但是有一个错误,即使我第一次尝试访问第一个网址时,也没有变量设置到该流程中,我将更改为第二个用于进行会话的时间。
- &GT;骡子版本3.4
答案 0 :(得分:2)
会话变量需要从一个流传递到另一个流。它们在事件中被序列化和反序列化。您在第一个流程中设置它并调用/自动完成,但读取它的流程正在侦听/ autocomplete2。
在/ autocomplete之后你不能单独命中/ autocomplete2并且期望会话变量在那里,因为它是在不同的事件上设置的。如果您希望在单独的流调用之间存储状态,请查看mule objectstore模块
http://mulesoft.github.io/mule-module-objectstore/mule/objectstore-config.html
关于Mule对象存储的信息:
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
答案 1 :(得分: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>