Commit 16bdbe7f by Nepxion

把订阅配置的初始化权限开放出去

parent 8a88f322
......@@ -11,6 +11,8 @@ package com.nepxion.discovery.plugin.configcenter.extension.nacos.adapter;
import java.util.concurrent.Executor;
import javax.annotation.PostConstruct;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -51,38 +53,42 @@ public class NacosConfigAdapter extends ConfigAdapter {
return configService.getConfig(serviceId, group, timeout);
}
@Override
public void subscribeConfig() throws Exception {
@PostConstruct
public void subscribeConfig() {
String groupKey = pluginContextAware.getGroupKey();
String group = pluginAdapter.getGroup();
String serviceId = pluginAdapter.getServiceId();
LOG.info("Subscribe remote config from Nacos server, {}={}, serviceId={}", groupKey, group, serviceId);
configService.addListener(serviceId, group, new Listener() {
@Override
public void receiveConfigInfo(String config) {
if (StringUtils.isNotEmpty(config)) {
LOG.info("Get config updated event from Nacos server, {}={}, serviceId={}", groupKey, group, serviceId);
RuleEntity ruleEntity = pluginAdapter.getRule();
String rule = ruleEntity.getContent();
if (!StringUtils.equals(rule, config)) {
fireRuleUpdated(new RuleUpdatedEvent(config), true);
try {
configService.addListener(serviceId, group, new Listener() {
@Override
public void receiveConfigInfo(String config) {
if (StringUtils.isNotEmpty(config)) {
LOG.info("Get config updated event from Nacos server, {}={}, serviceId={}", groupKey, group, serviceId);
RuleEntity ruleEntity = pluginAdapter.getRule();
String rule = ruleEntity.getContent();
if (!StringUtils.equals(rule, config)) {
fireRuleUpdated(new RuleUpdatedEvent(config), true);
} else {
LOG.info("Retrieved config is same as current config, ignore to update, {}={}, serviceId={}", groupKey, group, serviceId);
}
} else {
LOG.info("Retrieved config is same as current config, ignore to update, {}={}, serviceId={}", groupKey, group, serviceId);
}
} else {
LOG.info("Get config cleared event from Nacos server, {}={}, serviceId={}", groupKey, group, serviceId);
LOG.info("Get config cleared event from Nacos server, {}={}, serviceId={}", groupKey, group, serviceId);
fireRuleCleared(new RuleClearedEvent(), true);
fireRuleCleared(new RuleClearedEvent(), true);
}
}
}
@Override
public Executor getExecutor() {
return null;
}
});
@Override
public Executor getExecutor() {
return null;
}
});
} catch (Exception e) {
LOG.error("Subscribe config failed", e);
}
}
}
\ No newline at end of file
......@@ -9,22 +9,6 @@ package com.nepxion.discovery.plugin.configcenter.loader;
* @version 1.0
*/
import javax.annotation.PostConstruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class RemoteConfigLoader implements ConfigLoader {
private static final Logger LOG = LoggerFactory.getLogger(RemoteConfigLoader.class);
@PostConstruct
public void initialize() {
try {
subscribeConfig();
} catch (Exception e) {
LOG.error("Subscribe config failed", e);
}
}
protected abstract void subscribeConfig() throws Exception;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment