feature: hippo4j config model in nacos config before check

pull/1436/head^2
ayi 2 years ago
parent 5aa418c611
commit 86ec354959

@ -17,6 +17,8 @@
package cn.hippo4j.threadpool.dynamic.api; package cn.hippo4j.threadpool.dynamic.api;
import java.util.Map;
/** /**
* Bootstrap properties interface. * Bootstrap properties interface.
*/ */
@ -70,4 +72,11 @@ public interface BootstrapPropertiesInterface {
default Boolean getBanner() { default Boolean getBanner() {
return null; return null;
} }
/**
* Get nacos
*/
default Map<String, String> getNacos() {
return null;
}
} }

@ -17,6 +17,7 @@
package cn.hippo4j.core.enable; package cn.hippo4j.core.enable;
import cn.hippo4j.common.toolkit.MapUtil;
import cn.hippo4j.common.toolkit.StringUtil; import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.core.config.ConfigEmptyException; import cn.hippo4j.core.config.ConfigEmptyException;
import cn.hippo4j.threadpool.dynamic.api.BootstrapPropertiesInterface; import cn.hippo4j.threadpool.dynamic.api.BootstrapPropertiesInterface;
@ -26,6 +27,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.ConfigurableEnvironment;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
/** /**
@ -36,6 +38,7 @@ import java.util.Objects;
public class BeforeCheckConfiguration { public class BeforeCheckConfiguration {
private final String bootstrapPropertiesClassName = "cn.hippo4j.springboot.starter.config.BootstrapProperties"; private final String bootstrapPropertiesClassName = "cn.hippo4j.springboot.starter.config.BootstrapProperties";
private final String bootstrapConfigPropertiesClassName = "cn.hippo4j.threadpool.dynamic.mode.config.properties.BootstrapConfigProperties";
@Bean @Bean
public BeforeCheckConfiguration.BeforeCheck dynamicThreadPoolBeforeCheckBean(@Autowired(required = false) BootstrapPropertiesInterface properties, public BeforeCheckConfiguration.BeforeCheck dynamicThreadPoolBeforeCheckBean(@Autowired(required = false) BootstrapPropertiesInterface properties,
@ -68,6 +71,24 @@ public class BeforeCheckConfiguration {
"Please check whether the [spring.application.name] configuration is empty or an empty string."); "Please check whether the [spring.application.name] configuration is empty or an empty string.");
} }
} }
checkFlag = properties != null && Objects.equals(bootstrapConfigPropertiesClassName, properties.getClass().getName()) && properties.getEnable();
if (checkFlag) {
Map<String, String> nacos = properties.getNacos();
if (MapUtil.isNotEmpty(nacos)) {
String group = nacos.get("group");
if (StringUtil.isBlank(group)) {
throw new ConfigEmptyException(
"Web server failed to start. The dynamic thread pool config nacos group is empty.",
"Please check whether the [spring.dynamic.thread-pool.config-nacos-group] configuration is empty or an empty string.");
}
String dataId = nacos.get("data-id");
if (StringUtil.isBlank(dataId)) {
throw new ConfigEmptyException(
"Web server failed to start. The dynamic thread pool config nacos data-id is empty.",
"Please check whether the [spring.dynamic.thread-pool.config-nacos-data-id] configuration is empty or an empty string.");
}
}
}
return new BeforeCheckConfiguration.BeforeCheck(); return new BeforeCheckConfiguration.BeforeCheck();
} }

Loading…
Cancel
Save