首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在骡子上使用来自另一个流的变量值?

如何在骡子上使用来自另一个流的变量值?
EN

Stack Overflow用户
提问于 2014-07-08 14:16:49
回答 2查看 3.6K关注 0票数 1

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

代码:

代码语言:javascript
复制
<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>

另一个试图打印它的流程:

代码语言:javascript
复制
<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它们时,也没有将变量设置到该流中,我会将它们更改为seccond,在那里它希望有会话。

->骡子3.4版

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-07-08 14:29:32

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

您不能在/autocomplete2之后单独单击/autocomplete,并期望会话变量在设置为不同事件时存在。如果您希望在单独的流调用之间存储状态,请查看mule对象存储模块。

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

票数 2
EN

Stack Overflow用户

发布于 2014-07-08 15:28:28

您的流量如下:-

代码语言:javascript
复制
<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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24634159

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档