Merge pull request #391 from mabaiwan/develop

Hippo4j core configuration center validation judgment reconstruction
pull/393/head
小马哥 2 years ago committed by GitHub
commit e619fa12a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,91 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.hippo4j.core.springboot.starter.config;
import cn.hippo4j.core.springboot.starter.refresher.ApolloRefresherHandler;
import cn.hippo4j.core.springboot.starter.refresher.NacosCloudRefresherHandler;
import cn.hippo4j.core.springboot.starter.refresher.NacosRefresherHandler;
import cn.hippo4j.core.springboot.starter.refresher.ZookeeperRefresherHandler;
import com.alibaba.cloud.nacos.NacosConfigManager;
import com.alibaba.nacos.api.config.ConfigService;
import lombok.RequiredArgsConstructor;
import org.apache.curator.framework.CuratorFramework;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* Config handler configuration.
*/
@Configuration(proxyBeanMethods = false)
public class ConfigHandlerConfiguration {
private static final String NACOS_CONFIG_MANAGER_KEY = "com.alibaba.cloud.nacos.NacosConfigManager";
private static final String NACOS_DATA_ID_KEY = "nacos.data-id";
private static final String APOLLO_NAMESPACE_KEY = "apollo.namespace";
private static final String ZOOKEEPER_CONNECT_STR_KEY = "zookeeper.zk-connect-str";
@RequiredArgsConstructor
@ConditionalOnClass(ConfigService.class)
@ConditionalOnMissingClass(NACOS_CONFIG_MANAGER_KEY)
@ConditionalOnProperty(prefix = BootstrapCoreProperties.PREFIX, name = NACOS_DATA_ID_KEY)
static class EmbeddedNacos {
public final BootstrapCoreProperties bootstrapCoreProperties;
@Bean
public NacosRefresherHandler nacosRefresherHandler() {
return new NacosRefresherHandler(bootstrapCoreProperties);
}
}
@ConditionalOnClass(NacosConfigManager.class)
@ConditionalOnProperty(prefix = BootstrapCoreProperties.PREFIX, name = NACOS_DATA_ID_KEY)
static class EmbeddedNacosCloud {
@Bean
public NacosCloudRefresherHandler nacosCloudRefresherHandler() {
return new NacosCloudRefresherHandler();
}
}
@ConditionalOnClass(com.ctrip.framework.apollo.ConfigService.class)
@ConditionalOnProperty(prefix = BootstrapCoreProperties.PREFIX, name = APOLLO_NAMESPACE_KEY)
static class EmbeddedApollo {
@Bean
public ApolloRefresherHandler apolloRefresher() {
return new ApolloRefresherHandler();
}
}
@ConditionalOnClass(CuratorFramework.class)
@ConditionalOnProperty(prefix = BootstrapCoreProperties.PREFIX, name = ZOOKEEPER_CONNECT_STR_KEY)
static class EmbeddedZookeeper {
@Bean
public ZookeeperRefresherHandler zookeeperRefresher() {
return new ZookeeperRefresherHandler();
}
}
}

@ -27,10 +27,6 @@ import cn.hippo4j.core.springboot.starter.monitor.DynamicThreadPoolMonitorExecut
import cn.hippo4j.core.springboot.starter.monitor.LogMonitorHandler; import cn.hippo4j.core.springboot.starter.monitor.LogMonitorHandler;
import cn.hippo4j.core.springboot.starter.monitor.MetricMonitorHandler; import cn.hippo4j.core.springboot.starter.monitor.MetricMonitorHandler;
import cn.hippo4j.core.springboot.starter.notify.CoreNotifyConfigBuilder; import cn.hippo4j.core.springboot.starter.notify.CoreNotifyConfigBuilder;
import cn.hippo4j.core.springboot.starter.refresher.ApolloRefresherHandler;
import cn.hippo4j.core.springboot.starter.refresher.NacosCloudRefresherHandler;
import cn.hippo4j.core.springboot.starter.refresher.NacosRefresherHandler;
import cn.hippo4j.core.springboot.starter.refresher.ZookeeperRefresherHandler;
import cn.hippo4j.core.springboot.starter.refresher.event.AdapterExecutorsListener; import cn.hippo4j.core.springboot.starter.refresher.event.AdapterExecutorsListener;
import cn.hippo4j.core.springboot.starter.refresher.event.ExecutorsListener; import cn.hippo4j.core.springboot.starter.refresher.event.ExecutorsListener;
import cn.hippo4j.core.springboot.starter.refresher.event.PlatformsListener; import cn.hippo4j.core.springboot.starter.refresher.event.PlatformsListener;
@ -43,10 +39,13 @@ import cn.hippo4j.message.service.AlarmControlHandler;
import cn.hippo4j.message.service.HippoSendMessageService; import cn.hippo4j.message.service.HippoSendMessageService;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.*; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
@ -62,18 +61,14 @@ import org.springframework.core.annotation.Order;
@EnableConfigurationProperties(BootstrapCoreProperties.class) @EnableConfigurationProperties(BootstrapCoreProperties.class)
@ImportAutoConfiguration({UtilAutoConfiguration.class, MessageConfiguration.class}) @ImportAutoConfiguration({UtilAutoConfiguration.class, MessageConfiguration.class})
@ConditionalOnProperty(prefix = BootstrapCoreProperties.PREFIX, value = "enable", matchIfMissing = true, havingValue = "true") @ConditionalOnProperty(prefix = BootstrapCoreProperties.PREFIX, value = "enable", matchIfMissing = true, havingValue = "true")
@Import({
ConfigHandlerConfiguration.EmbeddedNacos.class, ConfigHandlerConfiguration.EmbeddedNacosCloud.class,
ConfigHandlerConfiguration.EmbeddedApollo.class, ConfigHandlerConfiguration.EmbeddedZookeeper.class
})
public class DynamicThreadPoolCoreAutoConfiguration { public class DynamicThreadPoolCoreAutoConfiguration {
private final BootstrapCoreProperties bootstrapCoreProperties; private final BootstrapCoreProperties bootstrapCoreProperties;
private static final String NACOS_CONFIG_MANAGER_KEY = "com.alibaba.cloud.nacos.NacosConfigManager";
private static final String NACOS_CONFIG_KEY = "com.alibaba.nacos.api.config.ConfigService";
private static final String APOLLO_CONFIG_KEY = "com.ctrip.framework.apollo.ConfigService";
private static final String ZK_CONFIG_KEY = "org.apache.curator.framework.CuratorFramework";
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@Order(Ordered.HIGHEST_PRECEDENCE) @Order(Ordered.HIGHEST_PRECEDENCE)
@ -96,35 +91,6 @@ public class DynamicThreadPoolCoreAutoConfiguration {
return new DynamicThreadPoolPostProcessor(bootstrapCoreProperties); return new DynamicThreadPoolPostProcessor(bootstrapCoreProperties);
} }
@Bean
@ConditionalOnClass(name = NACOS_CONFIG_KEY)
@ConditionalOnMissingClass(NACOS_CONFIG_MANAGER_KEY)
@ConditionalOnProperty(prefix = BootstrapCoreProperties.PREFIX, name = "nacos.data-id")
public NacosRefresherHandler nacosRefresherHandler() {
return new NacosRefresherHandler(bootstrapCoreProperties);
}
@Bean
@ConditionalOnClass(name = NACOS_CONFIG_MANAGER_KEY)
@ConditionalOnProperty(prefix = BootstrapCoreProperties.PREFIX, name = "nacos.data-id")
public NacosCloudRefresherHandler nacosCloudRefresherHandler() {
return new NacosCloudRefresherHandler();
}
@Bean
@ConditionalOnClass(name = APOLLO_CONFIG_KEY)
@ConditionalOnProperty(prefix = BootstrapCoreProperties.PREFIX, name = "apollo.namespace")
public ApolloRefresherHandler apolloRefresher() {
return new ApolloRefresherHandler();
}
@Bean
@ConditionalOnClass(name = ZK_CONFIG_KEY)
@ConditionalOnProperty(prefix = BootstrapCoreProperties.PREFIX, name = "zookeeper.zk-connect-str")
public ZookeeperRefresherHandler zookeeperRefresher() {
return new ZookeeperRefresherHandler();
}
@Bean @Bean
public DynamicThreadPoolMonitorExecutor hippo4jDynamicThreadPoolMonitorExecutor() { public DynamicThreadPoolMonitorExecutor hippo4jDynamicThreadPoolMonitorExecutor() {
return new DynamicThreadPoolMonitorExecutor(bootstrapCoreProperties); return new DynamicThreadPoolMonitorExecutor(bootstrapCoreProperties);

Loading…
Cancel
Save