How to stop and start the flow in Mule 4 programmatically
To be able to start and stop flows in Mule 4.x, you need to acquire the Mule Registry and then get the flow. This article provides a way to stop and start Mule flow using a Groovy script in Mule 4.x.
Also read: Filter keys with multiple values in array from JSON message using Dataweave
Follow the below-given steps
1. Add the scripting module to your project if it does not exist previously
2. Add a scripting component like the following:
scripting:execute engine="groovy" doc:name="Toggle flow" doc:id="33f6f071-dfef-5g3d-326d-256543d62d443" >
<scripting:code>
flow = registry.lookupByName("MyHelloWorldFlow").get();
if (flow.isStarted())
flow.stop()
else
flow.start()
</scripting:code>
</scripting:execute>
This particular script will start the flow with the name "MyHelloWorldFlow" if it is not started and stop it otherwise. Do not forget to replace "MyHelloWorldFlow" with the actual name of the flow that you wanted to start or stop. If you are using the Mule 3 version please follow the below link
Mule 3: https://support.mulesoft.com/s/article/How-to-start-stop-a-flow-programmatically
0 Comments