简体   繁体   中英

Mule 4 Groovy Script

Is there any way to call mule "flow" instance using groovy? like When I use the groovy script and it will call the another flow, that means ( calls the another flow -- > sets the variable value and get back with the results). = Expected Behaviour.

Requirement:

Like, Mule Flow A is running independently and keep on incrementing variable value.

Mule flow B wants to access the Flow A variable (Incremental value) ( only variable ) using groovy or python Script.

Note: Script should not execute flow A for getting variable value.

Is there method like to get instance of variable in groovy? like

flow=registry.lookupByName('A-flow').getInstance(VariableName)?

// Need to get only variable value.

Groovy Script to call a Mule flow:

 import org.mule.runtime.api.message.Message;
 import org.mule.runtime.core.api.event.CoreEvent;
 import org.mule.runtime.core.api.event.EventContextFactory;
 flow=registry.lookupByName('A-flow').grep();
 msg = Message.builder().value(payload).build();
 event =CoreEvent.builder(EventContextFactory.create(flow, org.mule.runtime.dsl.api.component.config.
    DefaultComponentLocation.fromSingleComponent("add-location"))).message(msg).build();
 result =flow.process(event);

Mule flow B wants to access the Flow A variable with out deploying or starting the flow A (as it is running independently ) using groovy or python Script.

Variables live inside a Mule Event , which is really what contains the status of an execution triggered from a flow. However even if you get a list of all active events you may not know which one is the one you are interested. It is also a bad practice trying to use Mule internals inside an application.

Instead you should share the value of the variable you are interested using a standard method for Mule, like an object store, a queue or database. It really depends on what you are trying to do and the design of your application what is the method that will fit best.

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