添加 apollo动态刷新线程池

pull/120/head
weihu 3 years ago
parent 294f8fd93a
commit 5e00d45939

@ -54,6 +54,15 @@
<version>2.2.5.RELEASE</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId>
<version>${apollo.version}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
</dependencies>
<build>

@ -0,0 +1,49 @@
package cn.hippo4j.core.starter.refresher;
import cn.hippo4j.core.executor.ThreadPoolNotifyAlarmHandler;
import cn.hippo4j.core.starter.config.BootstrapCoreProperties;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigChangeListener;
import com.ctrip.framework.apollo.ConfigFile;
import com.ctrip.framework.apollo.ConfigService;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
/**
* @author : wh
* @date : 2022/2/28 21:32
* @description:
*/
@Slf4j
public class ApolloRefresherHandler extends AbstractCoreThreadPoolDynamicRefresh implements ConfigChangeListener, InitializingBean {
private static final String APOLLO_PROPERTY = "${apollo.bootstrap.namespaces:application}";
@Value(APOLLO_PROPERTY)
private String namespace;
public ApolloRefresherHandler(ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler, ConfigParserHandler configParserHandler, BootstrapCoreProperties bootstrapCoreProperties) {
super(threadPoolNotifyAlarmHandler, configParserHandler, bootstrapCoreProperties);
}
@Override
public void onChange(ConfigChangeEvent configChangeEvent) {
ConfigFile configFile = ConfigService.getConfigFile(namespace,
ConfigFileFormat.fromString(bootstrapCoreProperties.getConfigFileType()));
String configInfo = configFile.getContent();
dynamicRefresh(configInfo);
}
@Override
public void afterPropertiesSet() {
String[] apolloNamespaces = this.namespace.split(",");
this.namespace = apolloNamespaces[0];
Config config = ConfigService.getConfig(namespace);
config.addChangeListener(this);
log.info("dynamic-thread-pool refresher, add apollo listener success, namespace: {}", namespace);
}
}

@ -47,6 +47,7 @@
<logback.version>1.2.3</logback.version>
<mybatis-plus.version>3.4.2</mybatis-plus.version>
<spring-boot.version>2.3.2.RELEASE</spring-boot.version>
<apollo.version>1.9.1</apollo.version>
<maven.javadoc.failOnError>false</maven.javadoc.failOnError>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>

Loading…
Cancel
Save