0
votes

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>
3
Are the sub-flow interactions dependent on each other? If not, you could parallelize them and each would die individually.David Dossot
They are kind of dependant. In each sub-flow I need to extract some data from teh web-service response and add it to the input paylaod. Then this becomes the paylaod for the next sub-flow.user1760178
As you said, result of one sub-flow becomes payload for another sub-flow, then it won't make much sense to call 2nd sub-flow w/o receiving response from first.Charu Khurana
@Learner is right: if the sub-flow interactions are dependent then why bother continuing the main flow if you can't fetch the data you need to proceed?David Dossot
As I said its a kind of enrichment without using the enricher directly. Because the enrichment is based on some logic. Its like The input is preserved. in each subflow a request is created from the payload which is suitable for the web-service call. Then from the response required data is extracted and enriched into the preserved input payload. Then this enriched paylaod is set as Paylaod to the next part.user1760178

3 Answers

1
votes

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

1
votes

One hack could be to store the payload in a variable, have a <catch-exception-strategy> block which will catch your web-service invoke exception, use <set-payload> to overwrite the current payload and then call sub-flow2 manually from catch-exception flow of sub-flow1

1
votes

For each web-service call, use a first-successful router, having your web-service call as the first child and the fall-back mechanism as the second one.