org.zodiac.autoconfigure.loadbalancer.BlockingAppLoadBalancerClientAutoConfiguration Maven / Gradle / Ivy
package org.zodiac.autoconfigure.loadbalancer;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.zodiac.autoconfigure.bootstrap.condition.ConditionalOnSpringCloudBootstrapDisabled;
import org.zodiac.autoconfigure.bootstrap.loadbalancer.AppLoadBalancerProperties;
import org.zodiac.autoconfigure.bootstrap.loadbalancer.AsyncAppLoadBalancerAutoConfiguration;
import org.zodiac.commons.constants.SystemPropertiesConstants;
import org.zodiac.core.bootstrap.loadbalancer.AppLoadBalancedRetryFactory;
import org.zodiac.core.bootstrap.loadbalancer.AppLoadBalancerClient;
import org.zodiac.core.loadbalancer.blocking.client.BlockingAppLoadBalancerClient;
import org.zodiac.core.loadbalancer.blocking.retry.BlockingLoadBalancedRetryFactory;
import org.zodiac.core.loadbalancer.core.LoadBalancerAppInstanceCookieTransformer;
import org.zodiac.core.loadbalancer.support.AppLoadBalancerClientFactory;
@SpringBootConfiguration
@EnableLoadBalancerClients
@ConditionalOnSpringCloudBootstrapDisabled
@ConditionalOnClass(value = {org.springframework.web.client.RestTemplate.class})
@AutoConfigureAfter(value = {AppLoadBalancerAutoConfiguration.class})
@AutoConfigureBefore(value = {org.zodiac.autoconfigure.bootstrap.loadbalancer.AppLoadBalancerAutoConfiguration.class, AsyncAppLoadBalancerAutoConfiguration.class})
public class BlockingAppLoadBalancerClientAutoConfiguration {
@Bean
@ConditionalOnMissingBean
@ConditionalOnBean(value = {AppLoadBalancerClientFactory.class})
protected AppLoadBalancerClient blockingLoadBalancerClient(AppLoadBalancerClientFactory loadBalancerClientFactory,
AppLoadBalancerProperties properties) {
return new BlockingAppLoadBalancerClient(loadBalancerClientFactory, properties);
}
@Bean
@ConditionalOnProperty(value = SystemPropertiesConstants.Zodiac.SPRING_BOOTSTRAP_LOADBALANCER_STICK_SESSION_ADD_INSTANCE_COOKIE,
havingValue = "true")
@ConditionalOnMissingBean(LoadBalancerAppInstanceCookieTransformer.class)
protected LoadBalancerAppInstanceCookieTransformer
loadBalancerServiceInstanceCookieTransformer(AppLoadBalancerProperties properties) {
return new LoadBalancerAppInstanceCookieTransformer(properties.getStickySession());
}
@SpringBootConfiguration
@ConditionalOnSpringCloudBootstrapDisabled
@ConditionalOnClass(value = {org.springframework.retry.support.RetryTemplate.class})
//@EnableConfigurationProperties(value = {AppLoadBalancerProperties.class})
protected static class BlockingAppLoadBalancerRetryConfig {
@Bean
@ConditionalOnMissingBean
AppLoadBalancedRetryFactory loadBalancedRetryFactory(AppLoadBalancerProperties properties) {
return new BlockingLoadBalancedRetryFactory(properties);
}
}
}