0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Spring WebFlux WebClientにタイムアウトを設定する

Last updated at Posted at 2018-05-31
@Bean
public WebClient webClient() {
    ReactorClientHttpConnector connector =
            new ReactorClientHttpConnector(builder -> {
                builder.onChannelInit(c -> {
                    c.config().setConnectTimeoutMillis(2 * 1000);
                    c.pipeline().addLast(new ReadTimeoutHandler(5, TimeUnit.SECONDS));
                    return false;
                });
            });
   return WebClient.builder().clientConnector(connector).build();
}

reactor - Spring 5 webflux how to set a timeout on Webclient - Stack Overflow
基本的にここに書いてある内容、なのだが……。
まず、SO_TIMEOUTは設定してもwarnでそんなオプションはないと警告が出る。多分使えないと思う。
onChannelInitだが、booleanを返すInterfaceになっている。とりあえずtrueを返しておけばいいだろうと雑な対応をするとchannelが閉じられ、使おうとするとNIO系のなんかExceptionが出て死ぬ。使いたかったらfalseで返す必要がある。
一応動作確認したので、これで動くと思います。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?