DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Explore Salesforce OAuth Authorization Flows and Its Use Cases
  • Build a Flow Collectibles Portal Using Cadence (Part 2)
  • Build a Digital Collectibles Portal Using Flow and Cadence (Part 1)
  • A Better Web3 Experience: Account Abstraction From Flow (Part 1)

Trending

  • Developers Beware: Slopsquatting and Vibe Coding Can Increase Risk of AI-Powered Attacks
  • What Is Plagiarism? How to Avoid It and Cite Sources
  • Operational Principles, Architecture, Benefits, and Limitations of Artificial Intelligence Large Language Models
  • A Developer's Guide to Mastering Agentic AI: From Theory to Practice

Stop and Start Mule Flow Dynamically at Runtime

Learn to stop a Mule flow at runtime to avoid unnecessary message processing and error handling when the external endpoint is unavailable.

By 
Khushboo Tripathi user avatar
Khushboo Tripathi
·
Jul. 08, 17 · Tutorial
Likes (7)
Comment
Save
Tweet
Share
14.6K Views

Join the DZone community and get the full member experience.

Join For Free

There is sometimes a requirement to stop the Mule flow dynamically when an external endpoint is not accessible to hold the processing of a message until the endpoint is available. This is to avoid the unnecessary processing of the message and error handling.

Example: a Mule process tries to connect to the external database and the database is not accessible. After the Mule process fails to connect with the database for a predefined interval, then the Mule process logs the error and stops processing further messages.

This has been achieved by using a Groovy script to start and stop Mule flow dynamically.

Sample Mule Flow: the Mule flow receives the HTTP request and inserts the request parameter to the database. If there is a database connectivity error then it executes the sub-flow to stop the Mule flow.

Image title

In this example, the Mule process tries to insert the data into the database, and if there is any error, a Choice exception will catch the exception as mentioned in the Mule expression. If there is any database connection error this will go through the ‘Catch Database Exception’ and will call the sub-flow ‘demoStopFlow.’

Stopping the Process at Runtime Using the Groovy Script Without User Intervention

suspend flow

This flow will check the flag condition. If it is true, then it executes the Groovy script to stop the process, or otherwise execute the default condition.

Below is the Groovy script, which will stop the specified process:

  <scripting:component doc:name="Groovy">
                    <scripting:script engine="Groovy">
                    <![CDATA[if(muleContext.registry.lookupFlowConstruct(flowVars.demoStartFlow).isStarted()                       && demo.test.isdb.stop=='true')
                        {
                                           muleContext.registry.lookupFlowConstruct(flowVars.demoStartFlow).stop();
flowVars.pubSuspendstatus=flowVars.demoStartFlow+' Suspended now ';
          }
                       else
                        {
         flowVars.pubSuspendstatus='Process already suspended';
             }            
               ]]></scripting:script>

If the process is in running status, it will stop the mentioned Mule process, or otherwise execute the else block and set the process status value.

Start the Process Without Any Deployment

Once the endpoint or target is up, then the support team can start the process without any deployment. The support team has to send a dummy message to the queue. This will check if the specified process is running or not. If it is stopped, then it will start the specified process.

Suspend flow

Here is the Groovy Script to start the flow:

<scripting:component doc:name="Groovy">
 <scripting:script engine="Groovy"> <![CDATA[
if(muleContext.registry.lookupFlowConstruct('demoFlow').isStopped()) {
muleContext.registry.lookupFlowConstruct('demoFlow').start();
flowVars.pubSuspendstatus='Process started now.';
} else {
flowVars.pubSuspendstatus='Processs already started';
}
          ]]>
</scripting:script>
</scripting:component>

This script first checks the condition. If it is stopped, this will start the mentioned flow, or otherwise execute the else condition and set the process status.

You can find the code on Github.

Flow (web browser)

Opinions expressed by DZone contributors are their own.

Related

  • Explore Salesforce OAuth Authorization Flows and Its Use Cases
  • Build a Flow Collectibles Portal Using Cadence (Part 2)
  • Build a Digital Collectibles Portal Using Flow and Cadence (Part 1)
  • A Better Web3 Experience: Account Abstraction From Flow (Part 1)

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!