HttpClient from offers various "timeouts" to be configured, two slightly confuses me:
- responseTimeout:
This is time that takes to receive a response after sending a request - ReadTimeoutHandler:
Raises a ReadTimeoutException when no data was read within a certain period of time
Could someone please explain the key difference between them?
Generic scenario - make a call using spring reactive WebClient, that uses HttpClient under the hood:
- establish connection to remote server >>> here we leverage
ChannelOption.CONNECT_TIMEOUT_MILLIS - TLS handshake >>> here we leverage
ReadTimeoutHandleras I am correct? - Send request
- ...wait...
- Receive response >>> which "timeout" takes precedence here: response/read?
If you use WebFlux and Netty, the
httpClientshould be the NettyhttpClient. Did you have a look there? https://projectreactor.io/docs/netty/release/api/reactor/netty/http/client/HttpClient.htmlConnect timeOut -> this is correct, if you can't connect to the remote server for any reason, this timeOut will be used.
TLS handshake, check:
reactor.netty.http.client.HttpClient#secure(): If not configured otherwise, Netty will assume 10 seconds timeout for the handshake. If you want to define another timeout, usereactor.netty.tcp.sslHandshakeTimeouthttps://projectreactor.io/docs/netty/release/api/reactor/netty/http/client/HttpClient.html#secure--The connection is now established and you send your request. By using
ReadTimeoutHandleryou can define how long to wait until you receive data over the connection. This could be for example the whole response in one go, or bytes if the responses is streamed.responseTimeoutinhttpClientdoes the same. Both create theTcpClientwith the giventimeOutsetting. The benefit of ReadTimeoutHandler is that you get a callback that executes logic you defined when the timeout occurs.