From the technical center of excellence of Massil Technologies, our technology leaders make it easy to understand the complex situations you come across in Mule ESB from the experience of Massil Technologies to have countered them in their experience of working on client projects in real time. This blog introduces how to consume an exception from a Mule ESB flow invoked from an until-successful scope. This blog is a part of series of blogs being authored and published by Massil Technologies for the benefit of the IT community globally.
In one another noticeable situation, we have come across while using Mule ESB until-successful scope to perform a wait-and-retry on a call to a REST API that can return a “rate limiting” response along with an HTTP response header containing a retry-duration time limit. As it is needed to handle the rate-limiting exception (to get the retry duration), we made the scope invoke a synchronous flow containing its own exception strategy. If we do not use a separate, synchronous flow the until-successful scope takes over catching the exception as its default behavior.
Our external-to-scope handling of the exception (which currently includes setting an exception message and code) is enough to stop the until-successful loop. We were in a situation to know if we can “consume” exceptions in a mule exception strategy and have execution continue the flow from the point the exception was?
Another area of debate is that if is it enough to not set any exception message payloads to consume an exception? We tried setting the payload to null after the exception was caught but the scope still terminated. We were in a dilemma if we were doomed to let the until-successful scope always handle exceptions, meaning we can’t interject with any exception handling of our own.
To overcome this situation we tried many options and the solution below seemed to be the best fit.
The most important part to notice is the failureExpression=”#[message.payloadAs(java.lang.String).equals(“FAILED”)]” setting and the set payload .
These two settings need to be configured to get the behavior desired.
Mule ESB Flow:
The most important part to notice is the failureExpression=”#[message.payloadAs(java.lang.String).equals(“FAILED”)]” setting and the set payload
<?xml version=“1.0” encoding=“UTF-8”?>
<http:request-config name=“HTTP_Request_Configuration” host=“www.google.co.nz” port=“80” doc:name=“HTTP Request Configuration”/>
<http:listener-config name=“HTTP_Listener_Configuration” host=“0.0.0.0” port=“8081” doc:name=“HTTP Listener Configuration”/>
<until-successful maxRetries=“3” millisBetweenRetries=“5000” doc:name=“Until Successful” synchronous=“true” failureExpression=“#[message.payloadAs(java.lang.String).equals("FAILED")]”>
<flow-ref name=“retryFlowConstruct” doc:name=“retryFlowConstruct”/>
<logger level=“INFO” doc:name=“Logger”/>
<catch-exception-strategy doc:name=“Catch Exception Strategy” enableNotifications=“false” logException=“false”>
<logger message=“privateFlowUntillSuccessful Exception encountered #[message]” level=“INFO” doc:name=“Logger”/>
<http:listener config-ref=“HTTP_Listener_Configuration” path=“/untill” doc:name=“HTTP”/>
<http:request config-ref=“HTTP_Request_Configuration” path=“/search?q=java.util.logging.Level” method=“GET” doc:name=“Google Search”/>
<logger message=“This logger will never be called” level=“INFO” doc:name=“Logger”/>
<catch-exception-strategy enableNotifications=“false” logException=“false” doc:name=“Catch Exception Strategy”>
<logger message=“Retry Failure #[exception]” level=“INFO” doc:name=“Logger”/>
<logger message=“Retry Failure Exception Payload: #[payload.getExceptionPayload().getException()]” level=“INFO” doc:name=“Logger”/>
<set-payload value=“#["FAILED"]” doc:name=“Set Payload”/>
This helped us consume an exception from a Mule ESB synchronous flow invoked from an until-successful scope. Hence, we have gone through the step by step process to depict the way Massil Technologies team has addressed the weird situation. Hope this article from Massil Technologies was useful for you. If you have any further queries on this topic, please reach out to email@example.com