Commit 16bdbe7f by Nepxion

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

parent 8a88f322
...@@ -11,6 +11,8 @@ package com.nepxion.discovery.plugin.configcenter.extension.nacos.adapter; ...@@ -11,6 +11,8 @@ package com.nepxion.discovery.plugin.configcenter.extension.nacos.adapter;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import javax.annotation.PostConstruct;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -51,38 +53,42 @@ public class NacosConfigAdapter extends ConfigAdapter { ...@@ -51,38 +53,42 @@ public class NacosConfigAdapter extends ConfigAdapter {
return configService.getConfig(serviceId, group, timeout); return configService.getConfig(serviceId, group, timeout);
} }
@Override @PostConstruct
public void subscribeConfig() throws Exception { public void subscribeConfig() {
String groupKey = pluginContextAware.getGroupKey(); String groupKey = pluginContextAware.getGroupKey();
String group = pluginAdapter.getGroup(); String group = pluginAdapter.getGroup();
String serviceId = pluginAdapter.getServiceId(); String serviceId = pluginAdapter.getServiceId();
LOG.info("Subscribe remote config from Nacos server, {}={}, serviceId={}", groupKey, group, serviceId); LOG.info("Subscribe remote config from Nacos server, {}={}, serviceId={}", groupKey, group, serviceId);
configService.addListener(serviceId, group, new Listener() { try {
@Override configService.addListener(serviceId, group, new Listener() {
public void receiveConfigInfo(String config) { @Override
if (StringUtils.isNotEmpty(config)) { public void receiveConfigInfo(String config) {
LOG.info("Get config updated event from Nacos server, {}={}, serviceId={}", groupKey, group, serviceId); 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(); RuleEntity ruleEntity = pluginAdapter.getRule();
if (!StringUtils.equals(rule, config)) { String rule = ruleEntity.getContent();
fireRuleUpdated(new RuleUpdatedEvent(config), true); 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 { } else {
LOG.info("Retrieved config is same as current config, ignore to update, {}={}, serviceId={}", groupKey, group, serviceId); LOG.info("Get config cleared event from Nacos server, {}={}, serviceId={}", groupKey, group, serviceId);
}
} else {
LOG.info("Get config cleared event from Nacos server, {}={}, serviceId={}", groupKey, group, serviceId);
fireRuleCleared(new RuleClearedEvent(), true); fireRuleCleared(new RuleClearedEvent(), true);
}
} }
}
@Override @Override
public Executor getExecutor() { public Executor getExecutor() {
return null; 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; ...@@ -9,22 +9,6 @@ package com.nepxion.discovery.plugin.configcenter.loader;
* @version 1.0 * @version 1.0
*/ */
import javax.annotation.PostConstruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class RemoteConfigLoader implements ConfigLoader { 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