---
schema_version: "1"
id: 14aa5417d44b324e50738122f99f4f55acab7f2c0be67bd9cceb5eda63450f07
title: Flow (<flow/>)
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/anypoint-code-builder/acb-component-flow.md
canonical_url: https://docs.mulesoft.com/anypoint-code-builder/acb-component-flow
source_site: docs.mulesoft.com
content_type: documentation
content_hash: f642f2051a58bc7c10e28403e959129bb0f31a3b58503812e7216c6356971cd7
description: MuleSoft Documentation Site
latest: true
---
---
product: Anypoint Code Builder
version: master
---

# Flow (<flow/>)

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

Group together a sequence of Core components and operations (provided by connectors and modules)
inside a scope to help automate integration processes.

Within a Mule application, a flow is a block of executable components, including any connector
operations, that Mule runtime executes sequentially on a Mule event. A flow can also contain an
event source, which triggers the creation of the event and the execution of the flow. You can create
more than one flow in your Mule app.

For a more in-depth discussion of uses, capabilities, and limits of flows and subflows, see
[Flows and Subflows](https://docs.mulesoft.com/mule-runtime/latest/about-flows).

Flows always function synchronously. To achieve asynchronous patterns, such as Fire-and-Forget, use
the [Async Scope](https://docs.mulesoft.com/anypoint-code-builder/acb-component-async).

## Component XML

This component supports the following XML structure:

```xml
<flow name="myFlow">

</flow>
```

Flow (`<flow/>`) attributes are configurable through the UI and XML.

<table><colgroup><col> <col> <col></colgroup><thead><tr><th>Attribute Name</th><th>Attribute XML</th><th>Description</th></tr></thead><tbody><tr><td><p><strong>name1</strong> (default)</p></td><td><p><code>name</code></p></td><td><div><div><p>Editable name for the component to display in the canvas.</p></div></div></td></tr><tr><td><p><strong>Initial state</strong></p></td><td><p><code>initialState</code></p></td><td><div><div><p>Indicates whether the flow is active when you start the application. Accepted values are <code>started</code> and <code>stopped</code>. You can trigger flows in state <code>started</code> from an internal or external Mule event source within the flow (such as an HTTP listener or Scheduler), by a Flow Reference from another flow or subflow, or through a call to the <a href="https://docs.mulesoft.com/dataweave/2.4/dataweave-runtime-functions#functions_runtime">lookup</a> DataWeave function.</p></div><div><p>If you set the initial state to <code>stopped</code>, use <a href="https://docs.mulesoft.com/runtime-manager/flow-management">Runtime Manager</a> to activate the flow or reset the Flow configuration to <code>Started</code>. The console output for this state is: <code>Flow flow_component_ex has not been started (initial state = 'stopped')</code></p></div><div><p>Defaults to <code>started</code>.</p></div></div></td></tr><tr><td><p><strong>Max concurrency</strong></p></td><td><p><code>maxConcurrency</code></p></td><td><div><div><p>Sets the maximum number of concurrent messages that the flow can process. If not set, the container thread pool determines the maximum number of threads the flow can use to optimize the performance when processing messages. While the flow is processing the maximum number of concurrent messages, it cannot receive additional requests.</p></div><div><p>Set <code>maxConcurrency</code> to <code>1</code> to cause the flow to process requests one at a time.</p></div><div><p>See <a href="https://docs.mulesoft.com/mule-runtime/latest/execution-engine#backpressure">Back-pressure</a> for details about the behavior of Mule runtime after it reaches the maximum concurrency value.</p></div></div></td></tr><tr><td><p>N/A</p></td><td><p><code>tracking:enable-default-event</code></p></td><td><div><div><p>When set to <code>true</code>, enables business events for Mule apps that you deploy to CloudHub.</p></div></div></td></tr><tr><td><p>N/A</p></td><td><p><code>tracking:transaction-id</code></p></td><td><div><div><p>Specifies the transaction ID for the business event. Requires <code>tracking:enable-default-event</code> set to <code>true</code>.</p></div></div></td></tr></tbody></table>

## Find Flows That Reference This Flow

To find every flow reference that calls a flow, right-click the flow in the canvas and select **Find
References**. You can also press Shift+Alt+F12 (Windows and macOS).

For more information, see
[Find Flows That Reference a Subflow](https://docs.mulesoft.com/anypoint-code-builder/int-configure-components#find-referencing-flows).

## Example: Flow and Subflows

The following example uses a Scheduler as a source to trigger the execution of the 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.

```xml
<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:

```json
{
  "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
    }
  }
}
```

## Error Handling

You can add an [Error Handler](https://docs.mulesoft.com/anypoint-code-builder/acb-component-error-handler) component to the Flow.

The following example sets the _myXML_ variable which contains an empty _<prices/>_ tag, then an
`<on-error-continue/>` returns an error because the DataWeave condition `isEmpty(payload.prices)`
returns `true`.

```xml
<flow name="flow_subflowFlow" >
  <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></prices>', 'application/xml')
 output application/xml
 ---
 myXml
]]></ee:set-payload>
    </ee:message>
  </ee:transform>
  <logger level="INFO" doc:name="Logger" message='#[payload.prices]'/>
  <error-handler >
    <on-error-continue enableNotifications="true" logException="true" doc:name="On Error Continue" type="EXPRESSION" when="#[isEmpty(payload.prices)]">
      <logger level="ERROR" doc:name="Logger" message='"An Error Occurred"'/>
    </on-error-continue>
  </error-handler>
</flow>
```

The resulting error message is as follows:

```text
ERROR 2018-07-30 23:58:45,293 [[MuleRuntime].cpuLight.06:
 [flow_subflow].flow_subflowFlow.CPU_LITE @1b1529b2]
 [event: 0-2aba3280-948f-11e8-82d0-f45c898f2549]
 org.mule.runtime.core.internal.processor.LoggerMessageProcessor:
 "An Error Occurred"
```

## See Also

- [Subflow](https://docs.mulesoft.com/anypoint-code-builder/acb-component-subflow)

- [Back-Pressure and MaxConcurrency](https://docs.mulesoft.com/mule-runtime/latest/tuning-backpressure-maxconcurrency)
