Like what you see? Sign up for our monthly newsletter

Mule has a new really cool module ready to be used in Muleforge called Dynamic Flows. The idea behind this new module might sound strange at first but it is actually quite simple: it allows you to add new flows to your existing mule application without restarting the server. It provides three simple operations for flow management:

1) Add

Creates a new mule context with the name and configuration provided. It allows adding to your application all the flows defined in the config XMLs passed to it. For example, the addFlow:

Receives a context name and a list of mule configs XMLs (the XMLs, not the files) through a http post, then the transformer creates a map grouping all the XMLs under the same key and finally the module processes those XMLs and creates a new context in your mule server. After the flow finishes, we have new flows ready to be used.

If we write: http://localhost:10443/run?contextName=testContext&flowName=testVmFlow on our web browser, it executes the dynamic flow called “testVmFlow” in the dynamic context “testContext” added by the module.

There are two ways you can call a flow: using a VM transport or without it. If you choose the first option, remember to declare the vm inbound in your flows.

3) Remove

Removes a entire dynamic context from your mule application.

A demo application

This module is quite useful when you need to execute logic that depends on dynamic information, for example, let’s consider the following requirement:

“Our users have several campaigns in Salesforce, all of them have a custom field called ‘info’. The information stored in this custom field depends on the campaign. For example, a user A has two campaigns: ‘Phone marketing’ and ‘Email sales’, for the first one, the field ‘info’ must contain all the user’s available twilio phone numbers separated by comas, but for the ‘Email sales’ campaign it must contain the email template stored in constant contact.

We need to create a mule application that sets the ‘info’ field for our users.”

As we can see, this problem is kind of tricky, because we don’t know which process we need to execute before hand, it depends on the salesforce campaign so what do we code in mule?, do we write an if condition in our mule context?, what happen if the user creates a third campaign?. Doing this application with the static mule configuration is hard, however we can simplify it a lot by using Dynamic Flows module. We just open MuleStudio, create the following flows:

And we are done, every time our users create a new campaign, they can tell mule how to get the data that has to stored into the ‘info’ field, without stopping and starting the mule server.

About the Author

Fernando is a Developer with a passion for math, software design, patterns, and agile methodologies. He is completing his PhD in Computer Science with specific focus in software requirement engineering, natural language processing, knowledge management, and AI agents.

Thanks Fernando, I was just curios how did you manage to add a plugin to MuleStudio since it comes packaged with embedded Mule runtime. Thanks for answering my question.

I think this plugin has a great potential, I would think it should be added to Mule standard distribution. I have a use case in which this plugin might address, still investigating but I managed to get it to work after fixing some Maven issues on my end.

So far there is no known issue with it, I’ve run some jmeter tests and it seems to behave correctly. It would be really nice to see it running on a production environment!, let me know if you need any help to get your code running, I’ll be following the blog and the forums to give you support if needed.

Yes, the schema is there. I just suspect that it’s Mule devkit related bug which is unable to properly scan the .xsd in the JAR. I can assert that I started to get this problem after the online schema was removed.

I am currently using Delete + Add to modify flow on the fly. So m question here is, what will happen to the message currently under processing when I delete a flow. Is there any flow state management? I mean like BPMs is there any flow state persistence mechanism in place

Thanks fernando for a quick reply. I have one more question, Is there a way to call the flows in main context from the dynamic flows? In other way can the dynamic flows call the flows from a differt context or mail context?

Each context has its own ExpressionManager, so it is not possible by default. But there is always a hack, in your child configuration create a MuleContextAware component that gets the ExpressionManager and registers the expression evaluator that you have in your parent (that is also in the context). It is kind of advance hack, fun to do…

Hello,
I’ve tested the dynamic flow and it’s working fine in Mule or MuleStudio. Thanks for the great work!
I have a question : Where should I put the plugins folder in an application deployed in an application server (Tomcat) ?