简体   繁体   中英

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. For all API we can do by mentioning the following in my yml file:

ribbon:
  ReadTimeout: 30000
  ConnectTimeout: 30000

But I want timeout increase timeout for a particular API. As it is a long process 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<> . See this answer.
  2. Use @Transactional annotation which takes a timeout (in seconds) parameter
    @GetMapping(value = { "", "/" })
    @Timed
    @Transactional(timeout = 120)  // 2 minutes
    public ResponseEntity<Page<DBInventoryMasterEntity>> fetch() {
        // your code
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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