简体   繁体   中英

How to use variable values from another flow on mule?

Im trying to access a value from session variable set into another flow

code:

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

and another flow trying to print it:

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

But there is an error saing there is no variable set into that flow even when i first try to access the first url them i change to the seccond where it was supose to have the session.

-> mule version 3.4

Session variables need to be passed from one flow to another. They are serialized and deserialized on the event. You're setting it in the first flow and calling /autocomplete but the flow thats reading it is listening on /autocomplete2.

You cannot hit /autocomplete2 separately after /autocomplete and expect the session variable to be there as it was set on a different event. If you are looking to store state between separate flow invocations take a look at the mule objectstore module

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

And info on Mule object stores here:

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

Some example configurations here:

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

Your flow will be something like the following :-

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM