【问题标题】:How to use variable values from another flow on mule?如何在 mule 上使用来自另一个流的变量值?
【发布时间】:2014-07-08 14:16:49
【问题描述】:

我正在尝试将会话变量中的值访问到另一个流中

代码:

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

但是有一个错误,即使我第一次尝试访问第一个 url,也没有在该流中设置变量,我将它们更改为应该进行会话的第二个。

-> 骡子版本 3.4

【问题讨论】:

    标签: session mule


    【解决方案1】:

    会话变量需要从一个流传递到另一个流。它们在事件中被序列化和反序列化。您在第一个流程中设置它并调用 /autocomplete,但正在读取它的流程正在侦听 /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

    【讨论】:

    • 您好,感谢您的反馈,这可能会回答我的问题,我会看看并尝试,您有任何示例代码可以用来实现我的吗?
    • 更新了答案,带有示例配置的链接。请注意,您需要通过 Maven 等添加 objectstore 模块。
    • 嗯,我找不到 objectStore 的架构......所以它一直给我一个错误,现在 mulesoft 只是不提供它......我在哪里可以找到它的任何线索?
    【解决方案2】:

    您的流程将类似于以下内容:-

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-17
      • 1970-01-01
      • 2012-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-27
      • 1970-01-01
      相关资源
      最近更新 更多