-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
➕ Chore: WebClientConfig dependency 누락 반영 (#31)
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/main/java/com/diareat/diareat/auth/config/WebClientConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<HttpClient, HttpClient> 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(); | ||
} | ||
} |