0

I have a scenario where the http connection needs to be closed if the server is sending more data than expected. i.e after a few seconds of receiving the data, I would like the close the connection automatically. Is this feasible?

Vijay Muvva
  • 1,063
  • 1
  • 17
  • 31

1 Answers1

0

You can specify a timeout on your RestTemplate. That way you can terminate any long running requests.

    @Bean
    public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) 
    {
        return restTemplateBuilder
           .setConnectTimeout(...)
           .setReadTimeout(...)
           .build();
    }
shinjw
  • 3,329
  • 3
  • 21
  • 42
  • I have tried this, still not working - RestTemplate restTemplate = new RestTemplateBuilder().setConnectTimeout(Duration.ofSeconds(20)) .setReadTimeout(Duration.ofSeconds(20)).build(); – Vijay Muvva Sep 02 '20 at 16:37