Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release #315

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading