Skip to content

Commit

Permalink
snutt-ev 연결 설정 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
Hank-Choi committed Jan 8, 2025
1 parent 44913e2 commit 4eb1cd0
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions core/src/main/kotlin/config/ApiWebClientConfig.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.wafflestudio.snu4t.config

import io.netty.channel.ChannelOption
import io.netty.handler.timeout.ReadTimeoutHandler
import io.netty.handler.timeout.WriteTimeoutHandler
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean
Expand All @@ -8,8 +11,11 @@ import org.springframework.context.annotation.Profile
import org.springframework.http.client.reactive.ReactorClientHttpConnector
import org.springframework.stereotype.Component
import org.springframework.web.reactive.function.client.WebClient
import reactor.netty.Connection
import reactor.netty.http.client.HttpClient
import reactor.netty.resources.ConnectionProvider
import java.time.Duration
import java.util.concurrent.TimeUnit

@Configuration
@EnableConfigurationProperties(ApiConfigs::class)
Expand All @@ -23,8 +29,25 @@ class ApiWebClientConfig(
}

private fun create(apiConfig: ApiConfig): WebClient {
val httpClient = HttpClient.create().responseTimeout(Duration.ofMillis(apiConfig.responseTimeout))
val connector = ReactorClientHttpConnector(httpClient)
val connector =
ReactorClientHttpConnector(
HttpClient.create(
ConnectionProvider.builder("snuttev-provider")
.maxConnections(100)
.pendingAcquireTimeout(Duration.ofMillis(300))
.maxLifeTime(Duration.ofSeconds(3600))
.maxIdleTime(Duration.ofSeconds(240))
.lifo()
.build(),
)
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, apiConfig.connectTimeout)
.doOnConnected { conn: Connection ->
conn
.addHandlerLast(ReadTimeoutHandler(apiConfig.readTimeout, TimeUnit.MILLISECONDS))
.addHandlerLast(WriteTimeoutHandler(apiConfig.readTimeout, TimeUnit.MILLISECONDS))
},
)

return WebClient.builder().clientConnector(connector).baseUrl(apiConfig.baseUrl).build()
}
}
Expand All @@ -36,7 +59,8 @@ class ApiConfigs {
}

class ApiConfig {
var responseTimeout: Long = 2000
var readTimeout = 3000L
var connectTimeout = 3000
lateinit var baseUrl: String
}

Expand Down

0 comments on commit 4eb1cd0

Please sign in to comment.