简体   繁体   English

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

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

I want to increase the timeout of an API at the controller level.我想在控制器级别增加 API 的超时时间。 For all API we can do by mentioning the following in my yml file:对于所有 API,我们可以通过在我的 yml 文件中提及以下内容来完成:

ribbon:
  ReadTimeout: 30000
  ConnectTimeout: 30000

But I want timeout increase timeout for a particular API.但我想超时增加特定 API 的超时时间。 As it is a long process API.因为它是一个长流程 API。 How can we achieve this?我们怎样才能做到这一点?

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

You can try these two methods:你可以试试这两种方法:

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

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

相关问题 如何使用 springboot 微服务创建两个实体 - How to create two entities using springboot microservices 如何使用 springboot 微服务获得用于跟踪的 req id? - How can i achieve req id for tracing using springboot microservices? 如何在我们使用 springboot 的 Rest API 应用程序中将域或 IP 地址列入白名单? - How can I whitelist Domain or IP address in a Rest API application in which we are using springboot? 如何在springboot中为微服务构建自定义存储库 - How to build customise repository in springboot for microservices 使用CloseableHttpClient增加超时时间 - Increase timeout duration using CloseableHttpClient 如何使用XML配置和JaxWsProxyFactoryBean增加Apache CXF超时? - How to increase Apache CXF timeout using XML configuration and JaxWsProxyFactoryBean? 我们如何在SpringBoot中使用@RequestBody传递列表和单独的字符串 - How can we pass a List and a separate String using @RequestBody in SpringBoot 如何增加AsyncRestTemplate类的超时时间? - How to increase timeout AsyncRestTemplate class? 如何增加泽西WS超时 - how to increase jersey WS timeout 在Java中使用ThreadPoolExecutor时如何通过超时取消特定任务? - How to cancel a particular task by timeout when using ThreadPoolExecutor in Java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM