From 7a53199fb8fca564b57d479c14eda568a900d530 Mon Sep 17 00:00:00 2001 From: asahi Date: Sat, 26 Apr 2025 18:37:17 +0800 Subject: [PATCH] =?UTF-8?q?doc:=20=E9=98=85=E8=AF=BBwebclient=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spring/webflux/webclient.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spring/webflux/webclient.md b/spring/webflux/webclient.md index bd840f7..e1c8e23 100644 --- a/spring/webflux/webclient.md +++ b/spring/webflux/webclient.md @@ -118,6 +118,20 @@ HttpClient httpClient = HttpClient.create() // Create WebClient... ``` + +##### readTimeoutHandler +在指定的时间内,如果channel没有执行读取操作,将会抛出ReadTimeoutException,并对channel执行关闭操作 + +> `没有数据被读取`的监控,是通过`IdleStateHandler`来实现的。 +> +> `ReadTimeoutHandler`继承了`IdleStateHandler`,当指定的readIdleTime过后,如果`channel`仍然没有指定任何的读操作,那么将会触发一个`IdleStateEvent`事件,并且事件状态为`IdleState.READER_IDLE` + +###### writeTimeoutHandler +而writeTimeoutHandler作用则如下: +- 其继承了`ChannelOutboundHandlerAdapter`,在通过write写入数据时,其会通过`ctx.executor()`指定一个`WriteTimeoutTask`,该task在指定timeout后被执行 +- 如果在writeTimeoutTask被执行时,写操作仍然没有处理完成,那么其将会触发一个WriteTimeoutException,并且channel也会被关闭。 + + 为所有请求配置response timeout: ```java HttpClient httpClient = HttpClient.create()