Contact Us 1-800-596-4880

Flow (<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 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.

Flows always function synchronously. To achieve asynchronous patterns, such as Fire-and-Forget, use the Async Scope.

Component XML

This component supports the following XML structure:

<flow name="myFlow">

</flow>

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

Attribute Name Attribute XML Description

name1 (default)

name

Editable name for the component to display in the canvas.

Initial state

initialState

Indicates whether the flow is active when you start the application. Accepted values are started and stopped. You can trigger flows in state started 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 lookup DataWeave function.

If you set the initial state to stopped, use Runtime Manager to activate the flow or reset the Flow configuration to Started. The console output for this state is: Flow flow_component_ex has not been started (initial state = 'stopped')

Defaults to started.

Max concurrency

maxConcurrency

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.

Set maxConcurrency to 1 to cause the flow to process requests one at a time.

See Back-pressure for details about the behavior of Mule runtime after it reaches the maximum concurrency value.

N/A

tracking:enable-default-event

When set to true, enables business events for Mule apps that you deploy to CloudHub.

N/A

tracking:transaction-id

Specifies the transaction ID for the business event. Requires tracking:enable-default-event set to true.

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.

<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
    }
  }
}

Error Handling

You can add an 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.

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

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"