---
schema_version: "1"
id: a3f21476322907db8f92b503910dfca21626ce00ec4414fec9b18e9c881b97f9
title: Round Robin (<component-xml-root/>)
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/anypoint-code-builder/acb-component-round-robin.md
canonical_url: https://docs.mulesoft.com/anypoint-code-builder/acb-component-round-robin
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 09d1ab2e7f78f827e337ae24a639e44abb993c185ee9531500cb6f86520b50bf
description: MuleSoft Documentation Site
latest: true
---
---
product: Anypoint Code Builder
version: master
---

# Round Robin (<component-xml-root/>)

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

Provide two or more processing routes, and execute only one of the routes each time the flow
executes the component.

Each route within Round Robin is a scope that can contain one or more processors. Starting with the
first route, Round Robin initiates execution of processors within the route over a Mule event and
sends the results to the next processor in the flow. Round Robin keeps track of the previously
selected route and never selects the same route consecutively. For example, the first time Round
Robin executes, the component selects the first route. The next time, it selects the second route.
If the previously selected route is the last route, Round Robin executes the first route.

The payload, variables, and attributes from the Mule event that reaches Round Robin are accessible
for processing within the route. Any changes to the Mule event within a route propagate to the
processor after Round Robin.

## Component XML

This component supports the following XML structure:

```xml
<round-robin
  doc:name="Round robin"
  doc:id="kaykco" >
  <!-- First processing route -->
  <route>
    <!-- Processors -->
  </route>
  <!-- Second processing route -->
  <route>
    <!-- Processors -->
  </route>

</round-robin>
```

Round Robin (`<round-robin/>`) 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>Round robin</strong> (default)</p></td><td><p><code>doc: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>N/A</p></td><td><p><code>doc:id</code></p></td><td><div><div><p>Automatically generated identifier for the component.</p></div></div></td></tr><tr><td><p>N/A</p></td><td><p><code>tracking:enable-default-events</code></p></td><td><div><div><p>When set to <code>true</code>, activates the Business Events feature.</p></div></div></td></tr></tbody></table>

`<route/>` is a child element of Round Robin.

<table><colgroup><col> <col></colgroup><thead><tr><th>Child Element</th><th>Description</th></tr></thead><tbody><tr><td><p><code>&lt;route/&gt;</code></p></td><td><div><div><p>Accepts one or more components as child elements for processing the Mule event. Multiple <code>&lt;route/&gt;</code> configurations are allowed.</p></div></div></td></tr></tbody></table>

## Example

The following example configures Round Robin with two processing routes:

```xml
<flow name="round-robin-ex" >
  <scheduler doc:name="Scheduler" > (1)
    <scheduling-strategy >
      <fixed-frequency frequency="10" timeUnit="SECONDS"/>
    </scheduling-strategy>
  </scheduler>
  <set-payload value="#[[1,2,3,4]]" doc:name="Set Payload" /> (2)
  <logger level="INFO" doc:name="Logger"
          category="PAYLOAD BEFORE ROUND ROBIN"
  	message="#[payload]"/> (3)
  <round-robin doc:name="Round Robin" >
    <route > (4)
      <set-payload value="#[payload - 4]" doc:name="Set Payload" />
      <logger level="INFO" doc:name="Logger"
              message="#[%dw 2.0&#10;output application/json&#10;---&#10;{ 'r1' : payload}]"
	      category="ROUTE 1 PAYLOAD"/>
    </route>
    <route > (5)
      <set-payload value="#[payload + 5]" doc:name="Set Payload" />
        <logger level="INFO" doc:name="Logger"
                message="#[%dw 2.0&#10;output application/json&#10;---&#10;{'r2' : payload}]"
                category="ROUTE 2 PAYLOAD"/>
    </route>
  </round-robin>
  <logger level="INFO" doc:name="Logger"
           message="#[payload]"
	   category="PAYLOAD OUTSIDE ROUND ROBIN"/> (6)
</flow>
```

<table><tbody><tr><td><i data-value="1"></i><b>1</b></td><td>Scheduler (<code>&lt;scheduler/&gt;</code>) executes the flow every 10 seconds.</td></tr><tr><td><i data-value="2"></i><b>2</b></td><td>Set Payload (<code>&lt;set-payload/&gt;</code>) provides the array <code>[1,2,3,4]</code>.</td></tr><tr><td><i data-value="3"></i><b>3</b></td><td>The Logger component <em>before</em> Round Robin prints the initial payload, <code>[1,2,3,4]</code>.</td></tr><tr><td><i data-value="4"></i><b>4</b></td><td>In the <em>first</em> route (<code>&lt;route/&gt;</code>) of Round Robin, a Set Payload component uses the DataWeave expression <code>payload - 4</code> to remove the last element of the initial payload, and the Logger in that route prints the resulting payload as the value of key <code>"r1"</code>, <code>{ "r1": [1,2,3] }</code>.</td></tr><tr><td><i data-value="5"></i><b>5</b></td><td>In the <em>second</em> route (<code>&lt;route/&gt;</code>) of Round Robin, a Set Payload component uses the DataWeave expression <code>payload + 5</code> to append a new element to the initial payload, and the Logger in that route prints the resulting payload as the value of key <code>"r2"</code>, <code>{ "r2": [1,2,3,4,5] }</code>.</td></tr><tr><td><i data-value="6"></i><b>6</b></td><td>The Logger component <em>after</em> Round Robin prints the payload of the route processed by an execution of Round Robin. The first execution prints <code>[1, 2, 3]</code>. The next execution prints <code>[1, 2, 3, 4, 5]</code>. The next prints <code>[1, 2, 3]</code>, and so on.</td></tr></tbody></table>

In the following excerpt, the logs show three executions of the Round Robin router. In this example,
the flow processes Mule events with IDs that begin `4df56260`, `53eb1c50`, and `59e12460`. (The
example is edited for readability.)

...

INFO 2022-12-19 10:02:30,233 ...event: 4df56260-7fc7-11ed-957f-147ddaaf4f97\] PAYLOAD BEFORE ROUND
ROBIN: \[1, 2, 3, 4\] INFO 2022-12-19 10:02:30,290 ...event: 4df56260-7fc7-11ed-957f-147ddaaf4f97\]
ROUTE 1 PAYLOAD: { "r1": \[1,2,3\] } INFO 2022-12-19 10:02:30,291 ...event:
4df56260-7fc7-11ed-957f-147ddaaf4f97\] PAYLOAD OUTSIDE ROUND ROBIN: \[1, 2, 3\]

INFO 2022-12-19 10:02:40,154 ...event: 53eb1c50-7fc7-11ed-957f-147ddaaf4f97\] PAYLOAD BEFORE ROUND
ROBIN: \[1, 2, 3, 4\] INFO 2022-12-19 10:02:40,167 ...event: 53eb1c50-7fc7-11ed-957f-147ddaaf4f97\]
ROUTE 2 PAYLOAD: { "r2": \[1, 2, 3, 4, 5\] } INFO 2022-12-19 10:02:40,168 ...event:
53eb1c50-7fc7-11ed-957f-147ddaaf4f97\] PAYLOAD OUTSIDE ROUND ROBIN: \[1, 2, 3, 4, 5\]

INFO 2022-12-19 10:02:50,151 ...event: 59e12460-7fc7-11ed-957f-147ddaaf4f97\] PAYLOAD BEFORE ROUND
ROBIN: \[1, 2, 3, 4\] INFO 2022-12-19 10:02:50,154 ...event: 59e12460-7fc7-11ed-957f-147ddaaf4f97\]
ROUTE 1 PAYLOAD: { "r1": \[1, 2, 3\] } INFO 2022-12-19 10:02:50,154 ...event:
59e12460-7fc7-11ed-957f-147ddaaf4f97\] PAYLOAD OUTSIDE ROUND ROBIN: \[1, 2, 3\]

...
