Skip to content

Commit

Permalink
feat: Deferred Loading Load Balancer Filter Class (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahoo-Wang authored Jul 2, 2024
1 parent 2329310 commit e5218f2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import org.springframework.web.reactive.function.client.WebClient

class WebClientFactoryBean(definition: CoApiDefinition) :
AbstractWebClientFactoryBean(definition) {
companion object {
private val loadBalancedFilterClass = LoadBalancedExchangeFilterFunction::class.java
}

override val builderCustomizer: WebClientBuilderCustomizer by lazy {
if (loadBalanced()) LoadBalancedWebClientBuilderCustomizer() else WebClientBuilderCustomizer.NoOp
if (!loadBalanced()) {
return@lazy WebClientBuilderCustomizer.NoOp
}
return@lazy LoadBalancedWebClientBuilderCustomizer()
}

inner class LoadBalancedWebClientBuilderCustomizer : WebClientBuilderCustomizer {
Expand All @@ -35,7 +35,7 @@ class WebClientFactoryBean(definition: CoApiDefinition) :
}
if (!hasLoadBalancedFilter) {
val loadBalancedExchangeFilterFunction =
appContext.getBean(loadBalancedFilterClass)
appContext.getBean(LoadBalancedExchangeFilterFunction::class.java)
it.add(loadBalancedExchangeFilterFunction)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ class RestClientFactoryBean(definition: CoApiDefinition) : AbstractRestClientFac
}

override val builderCustomizer: RestClientBuilderCustomizer by lazy {
if (loadBalanced()) LoadBalancedRestClientBuilderCustomizer() else RestClientBuilderCustomizer.NoOp
if (!loadBalanced()) {
return@lazy RestClientBuilderCustomizer.NoOp
}
return@lazy LoadBalancedRestClientBuilderCustomizer()
}

inner class LoadBalancedRestClientBuilderCustomizer : RestClientBuilderCustomizer {
Expand Down

0 comments on commit e5218f2

Please sign in to comment.