SubFlow Scope in Mule

SubFlow Scope in Mule

Subflows, which always run synchronously, inherit both the processing strategy and exception strategy of the flow that triggered its execution. Compared to keeping all message processing activity contained within a single flow, using a subflow to complete some message processing activities offers a few advantages:

A subflow can isolate logical processing blocks, making the graphical view more intuitive and the underlying XML code much easier to read.

Subflows are ideally suited for code reuse, so you can write a particular block of code once, then reference the same subflow repeatedly from within the same application. The diagram below offers an example of a subflow that is executed twice by different flow reference components in the same flow.

SubFlow example : 

Here flow reference is used to connect main flow with subflow.

flow reference configuration :

We need to give name of subflow in it.

URL : http://localhost:8085/api/subflow
Method : GET

When you hit the URL :

Output :

XML project code :

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="" xmlns="" xmlns:doc=""
    <http:listener-config name="HTTP_Listener_Configuration" host="" port="8085" basePath="/api" doc:name="HTTP Listener Configuration"/>
    <flow name="test_sub-flowFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/subflow" doc:name="HTTP"/>
        <logger message="---------In Main Flow-----------" level="INFO" doc:name="Logger"/>
        <flow-ref name="test_sub-flowSub_Flow" doc:name="Flow Reference"/>
        <logger message="-----------Again in Main Flow-------------" level="INFO" doc:name="Logger"/>
    <sub-flow name="test_sub-flowSub_Flow">
        <logger message="-----------In Sub Flow-------------" level="INFO" doc:name="Logger"/>