All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zodiac.autoconfigure.loadbalancer.AppLoadBalancerAutoConfiguration Maven / Gradle / Ivy

There is a newer version: 1.6.8
Show newest version
package org.zodiac.autoconfigure.loadbalancer;

import java.util.Collections;
import java.util.List;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.zodiac.autoconfigure.application.ApplicationInfoProperties;
import org.zodiac.autoconfigure.bootstrap.condition.ConditionalOnSpringCloudBootstrapDisabled;
import org.zodiac.autoconfigure.bootstrap.loadbalancer.reactive.ReactorAppLoadBalancerClientAutoConfiguration;
import org.zodiac.commons.constants.SystemPropertiesConstants;
import org.zodiac.core.bootstrap.loadbalancer.reactive.AppLoadBalancerBeanPostProcessorAutoConfiguration;
import org.zodiac.core.loadbalancer.annotation.AppLoadBalancerClientSpecification;
import org.zodiac.core.loadbalancer.config.AppLoadBalancerZoneConfig;
import org.zodiac.core.loadbalancer.support.AppLoadBalancerClientFactory;

@SpringBootConfiguration
@EnableLoadBalancerClients
@ConditionalOnSpringCloudBootstrapDisabled
//@EnableConfigurationProperties(value = {AppLoadBalancerProperties.class})
@ConditionalOnProperty(name = SystemPropertiesConstants.Zodiac.SPRING_BOOTSTRAP_LOADBALANCER_ENABLED, havingValue = "true")
@AutoConfigureBefore(value = {ReactorAppLoadBalancerClientAutoConfiguration.class, AppLoadBalancerBeanPostProcessorAutoConfiguration.class})
public class AppLoadBalancerAutoConfiguration {

    private final ApplicationInfoProperties applicationInfoProperties;
    private final ObjectProvider> configurations;

    public AppLoadBalancerAutoConfiguration(ApplicationInfoProperties applicationInfoProperties, ObjectProvider> configurations) {
        this.applicationInfoProperties = applicationInfoProperties;
        this.configurations = configurations;
    }

    @Bean
    @ConditionalOnMissingBean
    protected AppLoadBalancerZoneConfig zoneConfig(Environment environment) {
        //return new AppLoadBalancerZoneConfig(environment.getProperty("spring.bootstrap.loadbalancer.zone"));
        return new AppLoadBalancerZoneConfig(applicationInfoProperties.getZone());
    }

    @Bean
    @ConditionalOnMissingBean
    protected AppLoadBalancerClientFactory loadBalancerClientFactory() {
        AppLoadBalancerClientFactory clientFactory = new AppLoadBalancerClientFactory();
        clientFactory.setConfigurations(this.configurations.getIfAvailable(Collections::emptyList));
        return clientFactory;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy