简体   繁体   中英

Mule: Accessing counter variable from component inside foreach

I have a foreach element in my flow, which has a variable named "counter" set. Inside the foreach, I have a component, and I'm trying to get access to the "counter" variable from within the component. What is the proper way to get a hold of this variable from inside the component? Does it require adding a parameter to the method? I already have a parameter to take in the payload.

If we set the counter value in a property, we can get that property in inbound properties of message inside the component. some thing like this

 <set-variable variableName="counter" value="10" />
 <set-property propertyName="testout" value="#[counter]" doc:name="Property" />

Thanks-

Any variable from the mule flow can be accessed inside a Component by using the

muleMessage.getInvocationProperty("counter");

muleMessage can be obtained from MuleEventContext of the onCall(MuleEventContext arg0) method. Assuming that you have implemented Callable interface of mule.

If not, try getting the message from org.mule.RequestContext.getEvent().getMessage() This is RequestContext is deprecated as of now.

Hope this helps.

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