Sub Flow in Mule 4 | Flow Reference in Mule 4

Sub flow in Mule 4 | Flow Reference in Mule 4

Subflow is a scope that enables you to group event processors in a manner similar to that of a flow, but with certain differences and limitations:

1) Subflows do not have event sources.
2) Subflows do not have an error handling scope.
3) During design, sub-flow works as macros that replace the Flow Reference components that call them. When you build the application, all Flow Reference components that call a sub-flow are replaced by the contents of the referenced sub-flow.
4) Referencing sub-flows results in better performance than referencing a flow.

We can connect main flow with sub-flow in mule 4 via flow reference component.


Method: GET

XML project code:

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

<mule xmlns:http="" xmlns=""
       xmlns:xsi="" xsi:schemaLocation="">
       <http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="a4e501b9-6daa-4b7e-b0d5-af8f71e4538d" >
              <http:listener-connection host="" port="8085" />
       <flow name="test_subflowFlow" doc:id="1a446e09-90cc-49a2-9ce7-b90bddedb3db" >
              <http:listener doc:name="Listener" doc:id="3d4b5b66-8d9b-4742-b6aa-998272ea1905" config-ref="HTTP_Listener_config" path="/ref"/>
              <set-variable value="1" doc:name="Set Variable" doc:id="33ba4c59-98fd-44bb-a2ad-1847506b4ab0" variableName="var1"/>
              <flow-ref doc:name="Flow Reference" doc:id="f12a2f26-411d-4819-ae5d-7748d744a562" name="test_subflowSub_Flow"/>
       <sub-flow name="test_subflowSub_Flow" doc:id="3cdc536a-c92b-4217-88be-b58e224c6824" >
              <logger level="INFO" doc:name="Logger" doc:id="a6287bb5-0ee2-42cd-9107-e2593e2f4503" message="#[vars.var1]"/>