mirror of https://github.com/longtai-cn/hippo4j
parent
294f8fd93a
commit
5e00d45939
@ -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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue