Domanda

I have added a catch exception strategy inside a subflow, and I would like it to "restart" its subflow (as a goto, basically) whenever the catch is triggered.

So that it does something like this: FTPSubflow-> FTP->ERROR->Catch-> if (custom_retry_var > 0) > Restart FTPSubflow

I could have a java component in my catch to check that, but then I am not sure how to restart the subflow, and do it again. What I want to be sure is that when it restarts, if it succeeds a subsequent time, at the end of the subflow execution the execution of my regular flow will continue as normal, as it would have if a catch exception never happened.

Can Mule and a custom component be up to this?

Thanks!

È stato utile?

Soluzione

Sub-flows don't have their own exception handling. Exceptions triggered in sub-flow are processed by calling flows(main flow)

Private flows are another type of reusable flows, much similar to sub-flows but with a very different behavior in term of threading and exception handling. The primary reason for using a private flow instead of a sub-flow is to define in it a different exception strategy than from the calling flow (something that is impossible with a sub-flow).

Private flow is nothing but the main flow without the inbound endpoint. To start the flow again, make your flow main-flow, with an inbound endpoint and in your catch exception strategy, create a java component implementing Callable interface and use muleClient.dispatch to start flow again.

A sample component would be something like this:

import org.mule.api.MuleEventContext;
import org.mule.api.MuleMessage;
import org.mule.api.lifecycle.Callable;
import org.mule.api.client.MuleClient;

public class MyCustomComponent implements Callable {  


    @Override
    public Object onCall(MuleEventContext eventContext) throws Exception {
      MuleClient muleClient = eventContext.getMuleContext().getClient();
      muleClient.dispatch("jms://my.queue", "Message Payload", null);        
    }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top