'How to abandon a retry a REST http call when delay exceeded?

I make some HTTP requests to a remote platform, using something like the following code.

 WebClient.Builder builder = WebClient.builder().baseUrl("https://remote-platform.com/");

 response = webClient.get().uri(uri) //
     .header("KEY", ftxAccount.getKey()) //
     .header("TS", ts) //
     .header("SIGN", signature) //
     .accept(MediaType.APPLICATION_JSON).exchange().block();

All is well, but sometimes, the remote platform doesn't respond under 2 minutes. How to cancel my request if it is over 30 seconds, without waiting for network timeout?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source