【问题标题】:Spring Integration - http outbound gateway retry logic implementationSpring Integration——http出站网关重试逻辑实现
【发布时间】:2013-08-26 21:59:17
【问题描述】:

我正在通过 http 出站网关连接到 GET REST 服务。以下代码片段来自 spring 集成 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>

我想知道如何在此网关中设置重试机制,以便如果其余服务给出错误的响应代码,例如 400/500/404 ,出站网关应该能够自动重试特定的设定次数,直到它终于出错了。

我可以获取一个已实现的示例供我参考吗?

谢谢!

【问题讨论】:

    标签: spring http integration gateway outbound


    【解决方案1】:

    您可以在回复频道中处理回复。您可以使用服务激活器来处理它,解析响应,然后决定是否重试。请记住,回复频道中的回复是原始消息,因此您可以轻松地重新发送。

    【讨论】:

      【解决方案2】:

      你的情况已经被Spring处理了,你可以通过

              <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>
      

      我觉得参数挺清楚的,max尝试次数就是你想重发消息的recovery channel。 内部元素是等待时间

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-05-07
        • 1970-01-01
        • 1970-01-01
        • 2012-07-14
        相关资源
        最近更新 更多