2

Is there a way with either client (RestTemplate or the newer WebClient) to set per destination socket or connect timeouts? For example in an API aggregation web service, where I talk to several different services/hosts, it's often desirable to have different socket timeouts based on if the services are internal or external/3rd party. The only solution I know of (with RestTemplate, I haven't used WebClient) is to instantiate a separate RestTemplate with a different socket timeout/connect timeout (and do this for each host that requires a different timeout).

This is fairly annoying because the amount of setup code required for a RestTemplate configured with HttpComponents is non-trivial, and having to add @Qualifier at every use of RestTemplate injection is also non-ideal. Further, the fact that HttpComponents allows for max total connections and max routes to host implies that one RestTemplate talking to all outbound traffic is the expected usage.

Kevin
  • 24,871
  • 19
  • 102
  • 158
  • This question handles a similar problem (auth per host). I'm pretty sure, you can adapt it for your problem too: https://stackoverflow.com/questions/39957550/spring-boot-rest-template-and-rest-template-builder – ibexit Oct 24 '18 at 21:42

0 Answers0