Spring Integration - http outbound gateway retry logic implementation

1.5k views Asked by At

I am connecting to a GET REST service thorugh http outbound gateway. The following code snippent is from the spring integration XML

<http:outbound-gateway request-channel="dispatcherchannel"
    http-method="GET"
    url="http://ip:port/cacheAPI/Cache/fetch?employeeNumber={employeeNumber}"
    reply-channel="outboundreplychannel"
    expected-response-type="com.service.Employees">
<http:uri-variable name="empoyeeNumber" expression="payload"/>
</http:outbound-gateway>

I want to know how to set retry mechanism in this gateway so that if the rest service gives a bad response code like 400/500/404 , the oubound gateway should be able to retry automatically for a particular set number of times till it finally errors out.

Can I get a implemented sample for my reference?

Thanks!

2

There are 2 answers

0
AudioBubble On

you case its already handle by Spring and you can achieve through

        <int-http:request-handler-advice-chain >
        <int:retry-advice max-attempts="5" recovery-channel="channelWantSendMessagTo" >
            <int:exponential-back-off initial="1000" multiplier="5.0" maximum="600000" />
        </int:retry-advice>
    </int-http:request-handler-advice-chain>

I think the parameters is pretty clear, max attempts the number of attempts recovery channel where you want to resend the message. the inner element is for waiting time

0
andreadi On

You can handle the response in the reply channel. You can handle it with a service activator, parse the response and then decide for a retry or not. Keep in mind that in the reply channel along with the response is the original message, so you can easily resend.