Reputation: 2440
In Mule 3.4, how do I obtain the value of the Mule variable set from the "set-variable" tag in Java? Also how do I obtain values of Mule variables in different flows such as counter in flow1 and prevCounter in flow2? I can't find this on Mule's website.
Below is the Mule XML:
<mule xmlns:smtp="http://www.mulesoft.org/schema/mule/smtp" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:mongo="http://www.mulesoft.org/schema/mule/mongo" xmlns:quartz="http://www.mulesoft.org/schema/mule/quartz" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core" version="EE-3.4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd
http://www.mulesoft.org/schema/mule/mongo http://www.mulesoft.org/schema/mule/mongo/2.0/mule-mongo.xsd
http://www.mulesoft.org/schema/mule/quartz http://www.mulesoft.org/schema/mule/quartz/current/mule-quartz.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/smtp http://www.mulesoft.org/schema/mule/smtp/current/mule-smtp.xsd">
<quartz:connector name="Quartz3" validateConnections="true" doc:name="Quartz"/>
<flow name="flow1" doc:name="flow1">
<set-variable variableName="#['counter']" value="#[0]" doc:name="Variable"/>
<flow-ref name="flow2" doc:name="Flow Reference"/>
</flow>
<flow name="flow2" doc:name="flow2">
<logger level="INFO" doc:name="Logger"/>
<set-variable variableName="prevCounter" value="#[flowVars['counter']]" doc:name="Variable"/>
<set-variable variableName="counter" value="#[flowVars['counter']+1]" doc:name="Variable"/>
<choice doc:name="Choice">
<when expression="#[flowVars['counter']==5]">
<logger level="INFO" doc:name="Logger"/>
</when>
<otherwise>
<flow-ref name="flow2" doc:name="Flow Reference"/>
</otherwise>
</choice>
</flow>
</mule>
Upvotes: 1
Views: 909
Reputation: 1
Please try to create session variable or Flow variable in java and to retrive them in java MEL wont support you should use syntax some thing like message.getInvocationProperty('name') if those are flow variables.
Upvotes: 0
Reputation: 2319
Values stored with set-variable can be retrieved with MEL as flowVars['varName']
.
Take a look at this:
http://blogs.mulesoft.org/wp-content/uploads/2012/12/refcard-mel.pdf
Upvotes: 0
Reputation: 4015
You can get them from the Mule message with message.getInvocationProperty('counter')
.
Flow variables exist only during the flow of a message, so you can only access what was declared before in the same flow (or the flow that calls the current flow like you are doing right there in flow2). If you need them somewhere outside of the flow, you have to send them there from the flow.
Upvotes: 2