97008 48403
+91 40-27177600

Blog

How to consume an exception from a Mule ESB synchronous flow invoked from an until-successful scope?

single-blog

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

<?xml version=“1.0” encoding=“UTF-8”?>

 

<mule xmlns:http=“http://www.mulesoft.org/schema/mule/http”

xmlns=“http://www.mulesoft.org/schema/mule/core” xmlns:doc=“http://www.mulesoft.org/schema/mule/documentation”

xmlns:spring=“http://www.springframework.org/schema/beans”

xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”

xsi:schemaLocation=“http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd

http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd

http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd”>

<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”/>

<flow name=“privateFlowUntillSuccessful”>

<until-successful  maxRetries=“3” millisBetweenRetries=“5000” doc:name=“Until Successful” synchronous=“true” failureExpression=“#[message.payloadAs(java.lang.String).equals(&quot;FAILED&quot;)]”>

<flow-ref name=“retryFlowConstruct” doc:name=“retryFlowConstruct”/>

</until-successful>

<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”/>

</catch-exception-strategy>

</flow>

<flow name=“retryFlowConstruct”>

<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=“#[&quot;FAILED&quot;]” doc:name=“Set Payload”/>

</catch-exception-strategy>

</flow>

</mule>

 

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 info@massil.tech

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Get in touch with us

Scroll to top