http outbound retry with conditions (For checker condition)

隐身守侯 提交于 2021-02-10 04:50:09

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/37538019/http-outbound-retry-with-conditions-for-checker-condition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!