简体   繁体   中英

How to change state of a flow using groovy script in mule 4?

I have two flows, Flow 1 and Flow 2.

Flow 1

  • http listener - receive the request from external system.
  • groovy script ( change the initial state of the flow 2 )

flow 2

  • Jms on new message, read new message from queue.
  • http request to call system api.

Question: flow 1 step 2 - groovy script can this is possible?

Yes it is possible as explained in this article: How To Stop Or Start Flows In Mule 4.x Programmatically

You will need to perform the following steps:

  1. Add the scripting module to your project if you haven't previously added it.
  2. Add a scripting with a script similar to below:
 <scripting:execute engine="groovy" doc:name="Toggle flow"> <scripting:code> flow = registry.lookupByName(&quot;flowName&quot;).get(); if (flow.isStarted()) flow.stop() else flow.start() </scripting:code> </scripting:execute>

That Script will start the flow with name "flowName" if it is not started and stop it otherwise. Please replace "flowName" with the actual name of the flow you wish to start/stop or with a variable.

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