Harji
Harji

Reputation: 85

http outbound retry with conditions (For checker condition)

I want to make http outbound gateway call with retry condition. The outbound gateway will retry until the rest API that i have return ERROR or COMPLETE.

What i do is:

<int-http:outbound-gateway request-channel="checkJobChannel"
                           url="http://host/rest/job-status"
                           http-method="GET"
                           extract-request-payload="true"
                           expected-response-type="java.lang.String"
                           reply-timeout="10000"
                           reply-channel="checkJobChannel.reply"
                           auto-startup="true"
                           transfer-cookies="true">

then the router

@Router(inputChannel = "checkJobChannel.reply",applySequence = "true")
public String pointJob(Message<?>reply) {
    String returnChannel ="";
    if(reply.getPayload().get("status").equals("RUNNING")){
      returnChannel="checkJobChannel";
    }else if(reply.getPayload().get("status").equals("COMPLETE")|reply.getPayload().get("status").equals("ERROR")){
      returnChannel="nextChannel";  
    }
return returnChannel;
}

Can I do like that? Thanks. What the simple way to achieve that?

Upvotes: 3

Views: 150

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121550

Looks like that is good one. If you don't have any exceptions in return from that REST service, your simple approach with the router looks good to me.

You only can pay attention that there is a RequestHandlerRetryAdvice which you can place into your <int-http:outbound-gateway> to isolate the logic.

In addition you can take into account the RequestHandlerCircuitBreakerAdvice do not invoke your REST service according some condition.

But since you don't have an exception there, you will need to come up with some "struts" to requirements of those patterns.

You can find more info on the matter in the Reference Manual.

Upvotes: 1

Related Questions