Mule 4: Dynamically Call Multiple Subflows With One Flow-Ref
Learn how to dynamically call multiple sublows with a single Flow-Reference using Mule 4 and Anypoint Studio.
Join the DZone community and get the full member experience.Join For Free
In this tutorial, we will see how to call multiple subflows dynamically with the help of a single flow reference component.
As a first step, let's create a new Mule project using Anypoint Studio. After creating the project, we need to have all the subflow details listed under .properties/.yaml file.
Let's create a flow with HTTP Listener connector.
As a next step, let's assume we will get an attribute (header) as 'flowType' in our request. We will set a variable with a condition based on the header to route multiple subflows dynamically.
In the next step, we will add a Flow-Reference calling various subflows dynamically based on applied conditions.
In the final step, let's create different subflows as follows:
We can test the service after deploying the application in Anypoint Studio. You can use Postman/any other REST client to test the service.
The response will come back as follows (based on header that you send in your request)
I hope this article helps you understand how to call multiple subflows dynamically with the help of a single Flow-Reference.
Opinions expressed by DZone contributors are their own.