Contact Us 1-800-596-4880

Subflow (<sub-flow/>)

logo cloud IDE Cloud IDE

logo desktop IDE Desktop IDE

Group together a sequence of Core components and operations (provided by connectors and modules) inside a scope that you invoke from a Flow Reference in your Mule application.

The Subflow component works in a similar way to the Flow component but with the following differences:

  • Subflows do not support Mule event sources.

  • Subflows do not have a built-in error handling scope.

  • During design, subflows work as macros that replace the Flow Reference components that call them.

    When you build the application, Mule replaces all Flow Reference components that call a subflow with the contents of the referenced subflow.

  • Referencing subflows results in better performance than referencing a flow.

You can create multiple subflows in your Mule application.

For a more in-depth discussion of uses, capabilities, and limits of flows and subflows, see Flows and Subflows.

Limitations

Because the contents of a subflow replace each Flow Reference component that references that subflow, several instances of the event processors inside that subflow exist in the application at runtime. This behavior can cause issues with event processors that depend on unique IDs or instances to execute.

Component XML

This component supports the following XML structure:

<sub-flow name="mySubFlow">

</sub-flow>

Subflow (<sub-flow/>) attributes are configurable through the UI and XML.

Attribute Name Attribute XML Description

name1 (default)

name

Editable name for the subflow.

Example: Flow and Subflows

The following example uses a Scheduler as a source to trigger the execution of a flow every 10 seconds and then connects to a subflow (<sub-flow/>) through a Flow Ref (<flow-ref/>) component. The subflow then connects to another subflow, also using a Flow Ref component.

<flow name="flow_component_ex">
  <scheduler doc:name="Scheduler" >
    <scheduling-strategy >
      <fixed-frequency frequency="10" timeUnit="SECONDS"/>
    </scheduling-strategy>
  </scheduler>
  <ee:transform doc:name="Transform Message">
    <ee:message >
      <ee:set-payload ><![CDATA[
 %dw 2.0
 var myXml =  read('<prices>
    <basic>9.99</basic>
    <premium>53</premium>
    <vip>398.99</vip>
  </prices>', 'application/xml')
 output application/xml
 ---
 myXml
]]></ee:set-payload>
    </ee:message>
  </ee:transform>
  <flow-ref name="subflow_ex1"/>
</flow>
<sub-flow name="subflow_ex1">
  <ee:transform doc:name="Transform Message">
    <ee:message>
      <ee:set-payload><![CDATA[%dw 2.0
import * from dw::util::Timer
output application/json
var conversionRate=13
---
priceList: payload.prices mapObject(value, key, index) -> {
  (key) : {
       dollars: value,
       localCurrency: value * conversionRate,
       index_plus_1: index + 1,
       timer : currentMilliseconds()
   }
}]]>
      </ee:set-payload>
   </ee:message>
 </ee:transform>
 <flow-ref name="subflow_ex2"/>
</sub-flow>
<sub-flow name="subflow_ex2">
  <logger level="INFO" doc:name="Logger" message="#[payload]" />
</sub-flow>

The example produces the following output:

{
  "priceList": {
    "basic": {
      "dollars": "9.99",
      "localCurrency": 129.87,
      "index_plus_1": 1,
      "timer": 1533024312658
    },
    "premium": {
      "dollars": "53",
      "localCurrency": 689,
      "index_plus_1": 2,
      "timer": 1533024312659
    },
    "vip": {
      "dollars": "398.99",
      "localCurrency": 5186.87,
      "index_plus_1": 3,
      "timer": 1533024312659
    }
  }
}

See Also