srbhvatsa
srbhvatsa

Reputation: 98

Synchronous Until-Successful failure Expression not working

I have a groovy component inside Until-successful block which is throwing java.lang.IllegalArgumentException. In Until-Successful Failure Expression I am declaring expression #[exception.causedBy(java.lang.IllegalArgumentException)]

Now ideally it should be True and retries should happen only for this particular Exception but they are happening for every exception also. Even if I manually set failure expression as False by '#[false]' or i set a variable and compare its value with itself( comparing with value different from Variable itself), still it doesn't work.

<until-successful maxRetries="5" millisBetweenRetries="600" failureExpression="[exception.causedBy(java.net.SocketTimeoutException)]" doc:name="Until Successful" synchronous="true">
        <scripting:component doc:name="Groovy">
            <scripting:script engine="Groovy"><![CDATA[throw new IllegalArgumentException()]]></scripting:script>
        </scripting:component>
    </until-successful>

I just want it to retry for specific exceptions and for other exceptions it should throw exception without retrying.

Upvotes: 1

Views: 1884

Answers (1)

Tony K
Tony K

Reputation: 128

I guess you misunderstand how the Until-Successful scope works with a FailureExpression.

By reading again de documentation here, this scope works as follow :

  • By default, the Until-Successful retries if any exception is thrown within it. Thus, if now exception is thrown, no retry is attempted whatever the content of the payload or the header are
  • If a FailureExpression is configured, the Until-Successful retries if an exception is thrown OR if the FailureExpression if evaluated to true. Read this :

failureExpression : Specifies an expression that, when it evaluated to true, determines that the processing of one route was a failure. If no expression is provided, only an exception will be treated as a processing failure.

In your case, the Until-Successful scope indeed retries since your FailureExpression is evaluated to True. Replacing this expression by #[true] inevitably makes this scope to retry until the Maximum attempts configured is reached.

Hope it helps ;)

/Tony

Upvotes: 1

Related Questions