Until Successful
The Until Successful scope processes the components within it until they succeed or exhaust the maximum number of retries. UntilSuccessful runs synchronously. If a component within the scope fails to connect or produce a successful result, Until Successful retries the failed task until all configured retries are exhausted. If a retry succeeds, the scope proceeds to the next component. If the final retry does not succeed, UntilSuccessful produces an error.
Create a project in anypoint studio and configure the listener
Drag and drop Until Successful from mule palette
Configure the below parameters
- Max Retries: Specifies the maximum number of retries that are attempted
- Milliseconds Between Retries: Specifies the minimum interval between two attempts to process, in milliseconds, Default value is 1 Min
Wrap the HTTP Requester inside Until Successful
To replicate the UntilSuccessful Scope I have configured the Retries Interval as 30 ms (You can configure as per the requirement)
Configure the HTTP Requester and to replicate the failure Scenario configure the http response statue code as 500, in that case response will be treated as failure with http status code 500 and untilsuccessful will be executed
In Response section
Deploy the project and test the same from soapui
See the error ‘until-successful’ retries exhausted’ and Error Type is MULE:RETRY_EXHAUSTED
Message : 'until-successful' retries exhausted. Last exception message was: HTTP GET on resource 'http://dummy.restapiexample.com:80/api/v1/employees' failed with status code 200. Error type : MULE:RETRY_EXHAUSTED Element : org.mule.runtime.core.internal.routing.UntilSuccessful@2cd6f4a8 @ app:untilsuccessful.xml:15 (Until Successful) Element XML : <until-successful maxRetries="5" doc:name="Until Successful" doc:id="ed2a6567-029f-4b06-939f-f2d54f8c9516" millisBetweenRetries="30"> <http:request method="GET" doc:name="Request" doc:id="f3d39835-797a-4cca-9fad-2f5ac9e9942c" path="/api/v1/employees" config-ref="HTTP_Request_configuration"> <http:response-validator> <http:success-status-code-validator values="500"/> </http:response-validator> </http:request> </until-successful>
In case of success scenario there will not be any error received from Rest API(http status will be 200) and success response will be retrieved. In case of success either the UntilSuccessful scope will not be executed or it could be that the success response is received once retry succeed after few attempts
Sample application: Untilsuccessful sample application
Sample soapui project : untilsuccessful soapui project
you mentioned one snippet In Response section it should be a failure status code validator. instead of success status code validator.
correct if I am wrong.