Http Inbound Gateway 需要 2 倍超时时间才能向客户端发送超时响应

Http Inbound Gateway takes 2x timeout to send timeout response to client

我们正在使用 http 入站网关来处理 http 请求。最近,我们想设置特定的 http 响应代码,在超时后发送给用户。 我们升级到 spring 4.2.1 并设置

the reply-timeout-status-code-expression attribute

现在可以使用了。

但是有一个问题:如果我们将超时设置为 10 秒,Web 应用程序将在恰好 10 秒后引发 ReplyTimeoutException,但响应会在 20 秒后到达客户端(恰好是双倍的).

我们多次更改超时,但客户端收到响应总是需要 2 倍的超时时间。

这是 http 入站网关的 xml 配置:

<int-http:inbound-gateway id="inboundRequest" request-channel="inbound-channel" 
         supported-methods="POST" path="/Request" error-channel="errorChannel" reply-channel="gateway_response"
        reply-timeout="5000" request-payload-type="java.lang.String" reply-timeout-status-code-expression="'504'" >

非常感谢您的帮助

我看到你有一个 error-channel - 如果错误流 returns 没有响应,当错误流结束时回复计时器再次启动(我们正在等待错误流的回复).

您需要抛出 MessageTimeoutException.

而不是从错误流中返回任何内容

打开 DEBUG 日志记录并跟踪消息流是诊断此类问题的最佳方法。

如果这不是问题所在,您需要显示其余的配置(编辑问题,不要尝试在评论中 post 它)。