Search code examples
javamulemule-flow

Achieving Fail-safe behaviour in flow


I am trying to create a fail-safe scenario in my flow.

My flow looks like below. It involves some sub-flows which intern have call to web-services. In any scenario if one of the web-service is not available the connection-refused exception is thrown and the whole processing stops.

Instead I want a fail-safe scenario where the flow should continue with the next sub-flows even if the current out-bound call fails.

Is there any message processor or flow-control processor that could help acheive this behaviour in Mule.

Given below is my abstract flow

<flow name="main_flow" >
    ....
    ....
    <flow-ref  name="subflow_1" />
    ....
    ....
    <flow-ref  name="subflow_2" />
    ....
    ....
    <flow-ref  name="subflow_3" />
    ....
    ....

</flow>

<sub-flow name="subflow_1">
    ....
    ....
    <out-bound call to web-service />
    ....
    ....
</sub-flow>

<sub-flow name="subflow_2">
    ....
    ....
    <out-bound call to web-service />
    ....
    ....
</sub-flow>

<sub-flow name="subflow_3">
    ....
    ....
    <out-bound call to web-service />
    ....
    ....
</sub-flow>

Solution

  • You can achive the fail-safe behaviour with the flows.

    <flow name="main_flow" >
        ....
        ....
        <flow-ref  name="flow_1" />
        ....
        ....
        <flow-ref  name="flow_2" />
        ....
        ....
        <flow-ref  name="flow_3" />
        ....
        ....
    
    </flow>
    
    <flow name="flow_1" processingStrategy="synchronous" >
        ....
        ....
        <out-bound call to web-service />
        ....
        <catch-exception-strategy >
          .... Your FailSafe code to recover. Also you will have the exception here.
         </catch-exception-strategy>
    </flow>
    

    This way you can schieve the fail safe behaviour using the flows.

    Happy Coding :)