org.zodiac.autoconfigure.bootstrap.discovery.AppDiscoveryEnhancementAutoConfiguration Maven / Gradle / Ivy
package org.zodiac.autoconfigure.bootstrap.discovery;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.zodiac.autoconfigure.bootstrap.breaker.routing.AppRoutingProperties;
import org.zodiac.autoconfigure.bootstrap.condition.ConditionalOnAppDiscoveryEnabled;
import org.zodiac.autoconfigure.bootstrap.condition.ConditionalOnBreakerRoutingEnabled;
import org.zodiac.commons.constants.SystemPropertiesConstants;
import org.zodiac.core.application.AppContext;
import org.zodiac.core.application.AppInstanceManager;
import org.zodiac.core.application.DefaultAppInstanceManager;
import org.zodiac.core.bootstrap.AppDiscoveryContextRefresher;
import org.zodiac.core.bootstrap.breaker.routing.discovery.DiscoveryChooserAppRouter;
import org.zodiac.core.bootstrap.breaker.routing.discovery.RoutingDiscoveryInterceptor;
import org.zodiac.core.bootstrap.breaker.routing.service.AppRoutingService;
import org.zodiac.core.bootstrap.discovery.AppDiscoveryClient;
import org.zodiac.core.bootstrap.discovery.AppDiscoveryClientInterceptor;
import org.zodiac.core.bootstrap.discovery.server.AppDiscoveryStrategyReactiveFilter;
import org.zodiac.core.bootstrap.discovery.server.AppDiscoveryStrategyServletFilter;
@SpringBootConfiguration
@ConditionalOnAppDiscoveryEnabled
//@EnableConfigurationProperties(value = {AppDiscoveryStrategyProperties.class})
public class AppDiscoveryEnhancementAutoConfiguration {
public AppDiscoveryEnhancementAutoConfiguration() {
super();
}
@Bean
@ConfigurationProperties(prefix = SystemPropertiesConstants.Zodiac.SPRING_BOOTSTRAP_DISCOVERY_PREFIX, ignoreInvalidFields = true)
protected AppDiscoveryProperties appDiscoveryProperties() {
return new AppDiscoveryProperties();
}
@Bean
@ConfigurationProperties(prefix = SystemPropertiesConstants.Zodiac.SPRING_BOOTSTRAP_DISCOVERY_STRATEGY_PREFIX, ignoreInvalidFields = true)
protected AppDiscoveryStrategyProperties appDiscoveryStrategyProperties() {
return new AppDiscoveryStrategyProperties();
}
@Bean
@ConditionalOnMissingBean
protected AppInstanceManager appInstanceManager(AppDiscoveryClient discoveryClient) {
return new DefaultAppInstanceManager(discoveryClient);
}
@Bean
@ConditionalOnMissingBean
protected AppDiscoveryContextRefresher appDiscoveryContextRefresher(AppContext appContext) {
return new AppDiscoveryContextRefresher(appContext);
}
@SpringBootConfiguration
@ConditionalOnBreakerRoutingEnabled
@EnableConfigurationProperties(value = {AppRoutingProperties.class})
protected static class DiscoveryServiceRoutingAutoConfiguration {
public DiscoveryServiceRoutingAutoConfiguration() {
super();
}
@Bean
@ConditionalOnMissingBean
protected AppDiscoveryClientInterceptor appDiscoveryClientInterceptor(AppRoutingProperties routingProperties,
DiscoveryChooserAppRouter discoveryClientChooser) {
return new RoutingDiscoveryInterceptor(routingProperties, discoveryClientChooser);
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnBean(value = {AppRoutingService.class})
protected DiscoveryChooserAppRouter discoveryClientLoadBalancer(AppRoutingService routingService,
AppRoutingProperties routingProperties, AppContext appContext) {
return new DiscoveryChooserAppRouter(routingService, routingProperties, appContext);
}
}
@SpringBootConfiguration
@ConditionalOnAppDiscoveryEnabled
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
protected static class AppDiscoveryStrategyServletAutoConfiguration {
public AppDiscoveryStrategyServletAutoConfiguration() {
super();
}
@Bean
@ConditionalOnMissingBean
protected AppDiscoveryStrategyServletFilter
appDiscoprotectedveryStrategyServletFilter(AppDiscoveryStrategyProperties discoveryStrategyProperties) {
return new AppDiscoveryStrategyServletFilter(discoveryStrategyProperties);
}
}
@SpringBootConfiguration
@ConditionalOnAppDiscoveryEnabled
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
protected static class AppDiscoveryStrategyWebFluxAutoConfiguration {
public AppDiscoveryStrategyWebFluxAutoConfiguration() {
super();
}
@Bean
@ConditionalOnMissingBean
protected AppDiscoveryStrategyReactiveFilter
appDiscoveryStrategyWebFluxFilter(AppDiscoveryStrategyProperties discoveryStrategyProperties) {
return new AppDiscoveryStrategyReactiveFilter(discoveryStrategyProperties);
}
}
}