Session 如何在mule上使用来自另一个流的变量值?

Session 如何在mule上使用来自另一个流的变量值?,session,mule,Session,Mule,我试图从会话变量集访问另一个流中的值 代码: 另一个流正在尝试打印它: <flow name="test2" doc:name="test2" > <http:inbound-endpoint exchange-pattern="request-response" address="http://localhost:8081/services/autocomplete2" connector-ref="" transformer-refs="transform" d

我试图从会话变量集访问另一个流中的值

代码:


另一个流正在尝试打印它:

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

但有一个错误是,即使我第一次尝试访问第一个url时,也没有在该流中设置任何变量,因此我将其更改为第二次进行会话


->mule 3.4版会话变量需要从一个流传递到另一个流。它们在事件上被序列化和反序列化。您在第一个流中设置它并调用/autocomplete,但读取它的流正在侦听/autocomplete2

您不能在/autocomplete之后单独点击/autocomplete2并期望会话变量在那里,因为它是在其他事件上设置的。如果要在单独的流调用之间存储状态,请查看mule objectstore模块

有关Mule对象存储的信息,请参见:

以下是一些示例配置:


您的流程如下所示:-

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


您好,谢谢您的反馈,这可能会回答我的问题。我会看一看,然后再试一次。您有任何示例代码,我可以用来实现我的示例代码吗?更新了答案,并链接到示例配置。注意,您需要通过Maven等添加objectstore模块。我找不到objectstore的模式。。。所以它一直给我一个错误,现在mulesoft只是不提供它。。。我在哪里能找到它?
<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>