Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package co.nilin.opex.auth.config

import io.netty.channel.ChannelOption
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.cloud.client.loadbalancer.LoadBalanced
import org.springframework.context.annotation.Bean
Expand All @@ -9,13 +10,30 @@ import org.springframework.web.reactive.function.client.WebClient
import org.zalando.logbook.Logbook
import org.zalando.logbook.netty.LogbookClientHandler
import reactor.netty.http.client.HttpClient
import reactor.netty.resources.ConnectionProvider
import java.time.Duration

@Configuration
class WebClientConfig {

@Bean("keycloakWebClient")
fun keycloakWebClient(keycloakConfig: KeycloakConfig, logbook: Logbook): WebClient {
val client = HttpClient.create().doOnConnected { it.addHandlerLast(LogbookClientHandler(logbook)) }
val provider = ConnectionProvider.builder("keycloakPool")
.maxConnections(100)
.maxIdleTime(Duration.ofSeconds(30))
.maxLifeTime(Duration.ofMinutes(2))
.pendingAcquireTimeout(Duration.ofSeconds(60))
.evictInBackground(Duration.ofMinutes(1))
.build()

val client = HttpClient.create(provider)
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000)
.responseTimeout(Duration.ofSeconds(10))
.keepAlive(true)
.doOnConnected { it.addHandlerLast(LogbookClientHandler(logbook)) }

client.warmup().block()

return WebClient.builder()
.clientConnector(ReactorClientHttpConnector(client))
.baseUrl(keycloakConfig.url)
Expand Down
Loading