【问题标题】:Spring Boot - request timeout 504Spring Boot - 请求超时 504
【发布时间】:2022-09-28 21:50:41
【问题描述】:

我有两个相互交谈的 Spring Boot REST 应用程序。

ProjectA,getTest 休息服务有时需要一分钟。它从 projectB 调用。

  @PostMapping(value = \"/test\")
  public ResponseEntity<Map<byte[], List<String>>> getTest(
      @RequestBody ObjectDTO configDto) {
    try {

      HashMap<byte[], List<String>> testMap =
          serviceImpl.test(configDto);

      if (!testMap.isEmpty())
        return new ResponseEntity<>(testMap, HttpStatus.CREATED);
      else return new ResponseEntity<>(testMap, HttpStatus.NO_CONTENT);

    } catch (Exception e) {      
      return ResponseEntity.badRequest().build();
    }
  }

调用上述 API 的 ProjectB。

@PostMapping(value = \"/getTest\")
  @Async
  public ResponseEntity<Map<byte[], List<String>>> getTest(
      @RequestBody Config config) {
    try {
        Map<byte[], List<String>> val = serviceImpl.testConfig(config);
        return new ResponseEntity<>(val, HttpStatus.CREATED);       
    } catch (Exception e) {
      return ResponseEntity.badRequest().build();
    }
  }

它在本地工作,但是当我在 prod 上运行时,它总是在 6.2 秒后返回:

upstream request timeout

我已经在项目 B 上使用下面的配置增加了属性的超时,但没有工作。

server.tomcat.connection-timeout=120000
spring.mvc.async.request-timeout=120000

所以问题是如何修复 504 网关超时错误

    标签: spring rest timeout http-status-code-504


    【解决方案1】:

    看起来你有额外的代理服务器,它有自己的超时配置。

    【讨论】:

      猜你喜欢
      • 2019-07-13
      • 2016-04-23
      • 2016-09-13
      • 2018-09-11
      • 2016-08-16
      • 2021-06-23
      • 2021-05-16
      • 2018-01-20
      • 2013-12-18
      相关资源
      最近更新 更多