繁体   English   中英

我们正在使用微服务。 如何增加特定springboot api的超时?

[英]We are using microservices . How to increase timeout of a particular springboot api?

我想在控制器级别增加 API 的超时时间。 对于所有 API,我们可以通过在我的 yml 文件中提及以下内容来完成:

ribbon:
  ReadTimeout: 30000
  ConnectTimeout: 30000

但我想超时增加特定 API 的超时时间。 因为它是一个长流程 API。 我们怎样才能做到这一点?

@GetMapping(value = { "", "/" })
    public ResponseEntity<Page<DBInventoryMasterEntity>> fetch() {
        Page<DBInventoryMasterEntity> returnList = null;
            returnList = inventoryService.findByCustomerCode();
        return ResponseEntity.ok(returnList);
    }

你可以试试这两种方法:

  1. 返回一个Callable<> 看到这个答案。
  2. 使用带有超时(以秒为单位)参数的@Transactional 注释
    @GetMapping(value = { "", "/" })
    @Timed
    @Transactional(timeout = 120)  // 2 minutes
    public ResponseEntity<Page<DBInventoryMasterEntity>> fetch() {
        // your code
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM