Simulate while loop in Mule 3.4

半世苍凉 提交于 2019-12-05 17:37:34

A much simple approach that does not require any java code would be:

<flow name="stackoverflowFlow1" doc:name="stackoverflowFlow1">
        <vm:inbound-endpoint exchange-pattern="one-way" path="in" doc:name="VM"/>
        <set-variable variableName="#['counter']" value="#[0]" doc:name="Variable"/>
        <flow-ref name="stackoverflowFlow2" doc:name="Flow Reference"/>
    </flow>
    <flow name="stackoverflowFlow2" doc:name="stackoverflowFlow2">
        <logger level="INFO" doc:name="Logger"/>
        <set-variable variableName="counter" value="#[flowVars['counter']+1]" doc:name="Variable"/>
        <choice doc:name="Choice">
            <when expression="#[flowVars['counter']==10]">
                <logger level="INFO" doc:name="Logger"/>
            </when>
            <otherwise>
                <flow-ref name="stackoverflowFlow2" doc:name="Flow Reference"/>
            </otherwise>
        </choice>
    </flow>

In this case I'm stopping the the while after 10 iterations

Recursively calling the Flow will eventually end up with StackOverflowError. Tried it and it was thrown on he 70th+ iteration.

One of the alternatives was to place a loop inside a Custom-transformer then call the Flow/Endpoint programatically.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!