0

I have a simple spring-boot application which connects with mongodb and expose data. Here is my controller.

@RequestMapping(value = "/{coll}", method = RequestMethod.GET)
    public List<Map> retrieveMongoData(@PathVariable("collection") String collection ,
                                       @RequestParam Map<String,String> requestParams) throws Exception{

        Query query = new Query();  
        ........  
        return mongoTemplate.find(query, Map.class, collection);
    }

Now I need to add request timeouts to the REST API. Here explains a solution with return Callable.

In my case I return List<Map> in my controller. How I can implement time-out functionality while complying with my controller.

Shashika
  • 1,606
  • 6
  • 28
  • 47

1 Answers1

1

By following the link that you provided, you change the way your requests are processed from sync to async, this can solve your problem, but don't forget that this introduces new overhead ( in case your requests do not really require async processing). I think a better way would be to configure the embeded tomcat directly with a connection timeout, so I suppose by adding: server.tomcat.connection-timeout=20000 to the .properties file, this will make requests have a maximum time of 20s.

zakaria amine
  • 3,412
  • 2
  • 20
  • 35