diff --git a/src/main/java/com/diareat/diareat/auth/config/WebClientConfig.java b/src/main/java/com/diareat/diareat/auth/config/WebClientConfig.java new file mode 100644 index 0000000..24c82ff --- /dev/null +++ b/src/main/java/com/diareat/diareat/auth/config/WebClientConfig.java @@ -0,0 +1,39 @@ +package com.diareat.diareat.auth.config; + +import io.netty.channel.ChannelOption; +import io.netty.handler.timeout.ReadTimeoutHandler; +import io.netty.handler.timeout.WriteTimeoutHandler; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.client.reactive.ClientHttpConnector; +import org.springframework.http.client.reactive.ReactorClientHttpConnector; +import org.springframework.http.client.reactive.ReactorResourceFactory; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.netty.http.client.HttpClient; + +import java.time.Duration; +import java.util.function.Function; + +@Configuration +public class WebClientConfig { + + @Bean + public ReactorResourceFactory resourceFactory() { + ReactorResourceFactory factory = new ReactorResourceFactory(); + factory.setUseGlobalResources(false); + return factory; + } + + @Bean + public WebClient webClient() { + Function mapper = client -> HttpClient.create() + .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000) + .doOnConnected(connection -> connection.addHandlerLast(new ReadTimeoutHandler(10)) + .addHandlerLast(new WriteTimeoutHandler(10))) + .responseTimeout(Duration.ofSeconds(1)); + + ClientHttpConnector connector = + new ReactorClientHttpConnector(resourceFactory(), mapper); + return WebClient.builder().clientConnector(connector).build(); + } +} \ No newline at end of file