Dinesh
Dinesh

Reputation: 1

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

Upvotes: 0

Views: 512

Answers (1)

aled
aled

Reputation: 25699

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.

Upvotes: 1

Related Questions