|
1 | 1 | package dev.interview.server.ai.config; |
2 | 2 |
|
| 3 | +import io.netty.channel.ChannelOption; |
| 4 | +import io.netty.handler.timeout.ReadTimeoutHandler; |
| 5 | +import io.netty.handler.timeout.WriteTimeoutHandler; |
3 | 6 | import org.springframework.context.annotation.Bean; |
4 | 7 | import org.springframework.context.annotation.Configuration; |
5 | 8 | import org.springframework.http.MediaType; |
| 9 | +import org.springframework.http.client.reactive.ReactorClientHttpConnector; |
6 | 10 | import org.springframework.web.reactive.function.client.WebClient; |
7 | 11 | import org.springframework.http.HttpHeaders; |
| 12 | +import reactor.netty.http.client.HttpClient; |
| 13 | +import reactor.netty.resources.ConnectionProvider; |
| 14 | + |
| 15 | +import java.time.Duration; |
8 | 16 |
|
9 | 17 | @Configuration |
10 | 18 | public class WebClientConfig { |
11 | 19 | @Bean |
12 | 20 | public WebClient webClient(WebClient.Builder builder) { |
| 21 | + int maxConnections = 50; |
| 22 | + int maxIdleTime = 30; // 초 |
| 23 | + |
| 24 | + ConnectionProvider provider = ConnectionProvider.builder("fixed") |
| 25 | + .maxConnections(maxConnections) |
| 26 | + .maxIdleTime(Duration.ofSeconds(maxIdleTime)) // 유휴 커넥션 시간 |
| 27 | + .build(); |
| 28 | + |
| 29 | + HttpClient httpClient = HttpClient.create() |
| 30 | + .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 3000) |
| 31 | + .responseTimeout(Duration.ofSeconds(5)) |
| 32 | + .doOnConnected(conn -> |
| 33 | + conn.addHandlerLast(new ReadTimeoutHandler(5)) |
| 34 | + .addHandlerLast(new WriteTimeoutHandler(5)) |
| 35 | + ); |
| 36 | + |
13 | 37 | return builder |
14 | 38 | .baseUrl("http://localhost:6333") |
| 39 | + .clientConnector(new ReactorClientHttpConnector(httpClient)) |
15 | 40 | .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) // 수정된 부분 |
16 | 41 | .build(); |
17 | 42 | } |
|
0 commit comments