I have service activator method which throws database exception, I am catching that exception and sending ResponseEntity to the output channel. I have retry advice configured on the service activator but its doesn't retry(I am assuming its because I am catching it and sending custom exception to the output channel), I want it to retry 4 times first and then send custom exception. can you please how can I achieve it?
<int:chain id="a1-chain" input-channel="dRequestInputChannel" output-channel="dIntermediateChannel">
<int:service-activator ref="dAdapterController" method="dPersist">
<int:request-handler-advice-chain>
<int:retry-advice max-attempts="4" recovery-channel="dRetryChannel">
<int:exponential-back-off initial="1000" multiplier="5.0" maximum="60000" />
</int:retry-advice>
</int:request-handler-advice-chain>
</int:service-activator>
</int:chain>
<int:transformer input-channel="dRetryChannel" expression="payload.getFailedMessage()"/>
There is some piece of code after this in which I have a chain which has input channel as dIntermediateChannel and one router etc. which works fine! I meant to say flow works fine without retrying!
You said it yourself:
It is not clear what made you think that retry has to work in this case: if not exception is thrown from the user code, then nothing to
catch
in the retry interceptor and therefore no trigger to initiate retry policy.Please, don't confuse yourself and us. We don't know what is your code, but your say:
So, send it is a part of
ResponseEntity
or throw? I would say in the first case it is just custom reply and doesn't matter what is its body. As long as it does not causethrows
it is not an exception tocatch
.If you want a retry and then fallback, so take a look into a logic where you don't
catch
exception yourself, but let it to be done by theretry-advice
.To make a custom reply, you need to look into a
RecoveryCallback
injected into aRequestHandlerRetryAdvice
. Unfortunately, thatint:retry-advice
does not exposeRecoveryCallback
. An existingrecovery-channel
does not expect a reply to be produced from the publishing.Another way is to use an
ExpressionEvaluatingRequestHandlerAdvice
around this retry to catch the final exception and produce some compensation.