Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set timeouts per request using Spring REST Template?

I have an application that makes use of multiple rest clients. Each of those REST clients use the same Spring REST template bean. I was wondering if there was a way to set the timeout value per request using the Spring rest template?

like image 355
JCB Avatar asked Nov 09 '22 00:11

JCB


1 Answers

This worked for me...

RestTemplate restTemplate = new RestTemplate(getClientHttpRequestFactory());

private ClientHttpRequestFactory getClientHttpRequestFactory() {
    int timeout = 5000;
    HttpComponentsClientHttpRequestFactory clientHttpRequestFactory
      = new HttpComponentsClientHttpRequestFactory();
    clientHttpRequestFactory.setConnectTimeout(timeout);
    return clientHttpRequestFactory;
}
like image 86
Jason Delaney Avatar answered Nov 15 '22 06:11

Jason Delaney