Free MuleSoft CONNECT Keynote & Expo Pass Available!

Register now+
Nav

Round Robin Router

The Round Robin router iterates through a list of two or more routes in order, but it only routes to one of the routes each time it is executed. It keeps track of the previously selected route and never selects the same route consecutively. For example, the first time Round Robin executes, it selects the first route. The next time, it selects the second route. If the previously selected route is the last route in the list, Round Robin jumps to the first route.


       
    
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd">
        <flow name="round-robinFlow" doc:id="95d79691-4142-43b1-9719-7d6dc19c40bd" >
                <scheduler doc:name="Scheduler" doc:id="77a281f1-7643-422d-be72-25456b767d68" >
                        <scheduling-strategy >
                                <fixed-frequency />
                        </scheduling-strategy>
                </scheduler>
                <round-robin doc:name="Round Robin" doc:id="6fe1f667-05b2-47d3-81d2-e9ef27f7c9b6" >
                        <route>
                                <logger level="ERROR" doc:name="Logger" doc:id="e38d4396-d4ea-4eec-88dc-2bf60f579d5d" message="Route1"/>
                        </route>
                        <route>
                                <logger level="ERROR" doc:name="Logger" doc:id="6127fe32-0bc0-48e9-bb18-a9f3bfc45d0b" message="Route2"/>
                        </route>
                </round-robin>
        </flow>
</mule>

In the example above, the first time the Round Robin is executed it prints Route1. The next time, it prints Route2. The third time, since there are only two routes, Round Robin starts again with the first route and prints Route1.