【问题标题】:Is there a way to configure Spring Boot API to set connection timeout for incoming request?有没有办法配置 Spring Boot API 来设置传入请求的连接超时?
【发布时间】:2020-11-24 13:37:42
【问题描述】:

我已经在 Wildfly 10 上部署了我的高流量 SpringBoot 应用程序。该应用程序的服务器架构是 nginx(Angular 应用程序)->(反向代理)-> Wildfly 服务器。由于我们在几个小时内流量很大,因此 8080 端口(wildfly 应用程序端口)停留在 CLOSE_WAIT,因为 nginx 在一段时间后关闭了连接。

如果请求时间大于 5 秒,我希望配置 Spring Boot 应用程序以关闭连接。

例子:

@GetMapping("test1")
public ResponseEntity test1(){
    return ResponseEntity.ok("TESTED!");
}

@GetMapping("test2")
public ResponseEntity test2() throws InterruptedException{
    Thread.sleep(300000);
    return ResponseEntity.ok("TESTED!");
}

对于test2获取HTTP方法有没有办法配置spring boot application/Wildfly/centos为传入请求设置连接超时?

【问题讨论】:

    标签: java spring-boot jboss wildfly high-traffic


    【解决方案1】:

    您可以在application.properties. 中尝试server.connection-timeout=300000

    来自官方文档:

    server.connection-timeout= # 连接器在关闭连接之前等待另一个 HTTP 请求的时间(以毫秒为单位)。未设置时,将使用连接器的特定于容器的默认值。使用值 -1 表示没有(即无限)超时。

    或者您可以尝试使用@Transactional 注释并为其设置一个参数:

    @Transactional(timeout = 300000)

    【讨论】:

    • 它没有用。 server.connection-timeout 已弃用。我正在使用 Spring Boot 2.3。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-17
    • 1970-01-01
    • 1970-01-01
    • 2016-04-23
    • 2018-09-11
    • 1970-01-01
    相关资源
    最近更新 更多