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);
    }

1 answer

  • answered 2020-09-14 07:06 Ronij Pandey

    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
        }