0

I have the code like this:

var fac = new SimpleClientHttpRequestFactory();
fac.setConnectionTimeout(Duration.ofMillis(100))
fac.setReadTimeout(Duration.ofMillis(500))

var restClient = RestClient.builder().requestFactory(fac).build();

restClient.post().uri("...").header("...", "123").body("Some text").retrive().toEntity(String.class)

The problem is I expect this method to not take more than 500+100 + some extra overhead like 5 to 10 milliseconds.

But for some reason sometime it takes up to 5 seconds. Is there any other timeout I should set? Docs isn't super clear and is there any way to have full timeout of 700. I can think of creating threads, create a future and wait upto 600 and interrupt it, but that seems overkill

Thanks

6
  • Setting the timeout on the client side alone wont give you an answer as why the /server/ is taking 5s on some requests. you need to check the server side why those requests are taking 5s not your client. Commented May 20 at 3:35
  • Which Spring version are you using? Also you really should be creating a bean for the RestClient and not create it each time you need it. Commented May 20 at 8:10
  • @JorgeCampos Here, I don't care how much server gives. I want error eg TimeoutException if it takes more than 700ms. Commented May 21 at 2:02
  • @M.Deinum I am using spring verssion is 6.1.8 and apache httpcompoennts.client5 is 5.4.1 Commented May 21 at 2:04
  • You aren't using the Http Component library. The SimpleClientHttpRequestFactory uses the default JDK HTTP support and not the Apache HTTP Library. \ Commented May 21 at 7:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.