Commit 1ce7df7c by Nepxion

增加全局监听

parent 9420dae2
......@@ -61,7 +61,7 @@ public class NacosConfigAdapter extends ConfigAdapter {
String group = pluginAdapter.getGroup();
String serviceId = pluginAdapter.getServiceId();
LOG.info("Get config from Nacos server, {}={}, serviceId={}, globalConfig={}", groupKey, group, serviceId, globalConfig);
LOG.info("Get {} config from Nacos server, {}={}, serviceId={}", getConfigType(globalConfig), groupKey, group, serviceId);
return nacosOperation.getConfig(group, globalConfig ? group : serviceId);
}
......@@ -77,14 +77,14 @@ public class NacosConfigAdapter extends ConfigAdapter {
String group = pluginAdapter.getGroup();
String serviceId = pluginAdapter.getServiceId();
LOG.info("Subscribe config from Nacos server, {}={}, serviceId={}, globalConfig={}", groupKey, group, serviceId, globalConfig);
LOG.info("Subscribe {} config from Nacos server, {}={}, serviceId={}", getConfigType(globalConfig), groupKey, group, serviceId);
try {
nacosOperation.subscribeConfig(group, globalConfig ? group : serviceId, new NacosSubscribeCallback() {
@Override
public void callback(String config) {
if (StringUtils.isNotEmpty(config)) {
LOG.info("Get config updated event from Nacos server, {}={}, serviceId={}, globalConfig={}", groupKey, group, serviceId, globalConfig);
LOG.info("Get {} config updated event from Nacos server, {}={}, serviceId={}", getConfigType(globalConfig), groupKey, group, serviceId);
RuleEntity ruleEntity = pluginAdapter.getRule();
String rule = null;
......@@ -94,17 +94,21 @@ public class NacosConfigAdapter extends ConfigAdapter {
if (!StringUtils.equals(rule, config)) {
fireRuleUpdated(new RuleUpdatedEvent(config), true);
} else {
LOG.info("Retrieved config is same as current config, ignore to update, {}={}, serviceId={}, globalConfig={}", groupKey, group, serviceId, globalConfig);
LOG.info("Retrieved {} config from Nacos server is same as current config, ignore to update, {}={}, serviceId={}", getConfigType(globalConfig), groupKey, group, serviceId);
}
} else {
LOG.info("Get config cleared event from Nacos server, {}={}, serviceId={}, globalConfig={}", groupKey, group, serviceId, globalConfig);
LOG.info("Get {} config cleared event from Nacos server, {}={}, serviceId={}", getConfigType(globalConfig), groupKey, group, serviceId);
fireRuleCleared(new RuleClearedEvent(), true);
}
}
});
} catch (Exception e) {
LOG.error("Subscribe config from Nacos server failed, " + groupKey + "=" + group + ", serviceId=" + serviceId + ", globalConfig=" + globalConfig, e);
LOG.error("Subscribe " + getConfigType(globalConfig) + " config from Nacos server failed, " + groupKey + "=" + group + ", serviceId=" + serviceId, e);
}
}
private String getConfigType(boolean globalConfig) {
return globalConfig ? "global" : "partial";
}
}
\ No newline at end of file
......@@ -59,7 +59,7 @@ public class RedisConfigAdapter extends ConfigAdapter {
String group = pluginAdapter.getGroup();
String serviceId = pluginAdapter.getServiceId();
LOG.info("Get config from Redis server, {}={}, serviceId={}, globalConfig={}", groupKey, group, serviceId, globalConfig);
LOG.info("Get {} config from Redis server, {}={}, serviceId={}", getConfigType(globalConfig), groupKey, group, serviceId);
return redisOperation.getConfig(group, globalConfig ? group : serviceId);
}
......@@ -82,7 +82,7 @@ public class RedisConfigAdapter extends ConfigAdapter {
@Override
public void callback(String config) {
if (StringUtils.isNotEmpty(config)) {
LOG.info("Get config updated event from Redis server, {}={}, serviceId={}, globalConfig={}", groupKey, group, serviceId, globalConfig);
LOG.info("Get {} config updated event from Redis server, {}={}, serviceId={}", getConfigType(globalConfig), groupKey, group, serviceId);
RuleEntity ruleEntity = pluginAdapter.getRule();
String rule = null;
......@@ -92,17 +92,21 @@ public class RedisConfigAdapter extends ConfigAdapter {
if (!StringUtils.equals(rule, config)) {
fireRuleUpdated(new RuleUpdatedEvent(config), true);
} else {
LOG.info("Retrieved config is same as current config, ignore to update, {}={}, serviceId={}, globalConfig={}", groupKey, group, serviceId, globalConfig);
LOG.info("Retrieved {} config from Redis server is same as current config, ignore to update, {}={}, serviceId={}", getConfigType(globalConfig), groupKey, group, serviceId);
}
} else {
LOG.info("Get config cleared event from Redis server, {}={}, serviceId={}, globalConfig={}", groupKey, group, serviceId, globalConfig);
LOG.info("Get {} config cleared event from Redis server, {}={}, serviceId={}", getConfigType(globalConfig), groupKey, group, serviceId);
fireRuleCleared(new RuleClearedEvent(), true);
}
}
});
} catch (Exception e) {
LOG.error("Subscribe config from Redis server failed, " + groupKey + "=" + group + ", serviceId=" + serviceId + ", globalConfig=" + globalConfig, e);
LOG.error("Subscribe " + getConfigType(globalConfig) + " config from Redis server failed, " + groupKey + "=" + group + ", serviceId=" + serviceId, e);
}
}
private String getConfigType(boolean globalConfig) {
return globalConfig ? "global" : "partial";
}
}
\ No newline at end of file
......@@ -56,7 +56,7 @@ public class RedisConfigAutoConfiguration {
String group = pluginAdapter.getGroup();
String serviceId = pluginAdapter.getServiceId();
LOG.info("Subscribe config from Redis server, {}={}, serviceId={}, globalConfig=true", groupKey, group, serviceId);
LOG.info("Subscribe global config from Redis server, {}={}, serviceId={}", groupKey, group, serviceId);
return new MessageListenerAdapter(configAdapter, "subscribeGlobalConfig");
}
......@@ -67,7 +67,7 @@ public class RedisConfigAutoConfiguration {
String group = pluginAdapter.getGroup();
String serviceId = pluginAdapter.getServiceId();
LOG.info("Subscribe config from Redis server, {}={}, serviceId={}, globalConfig=false", groupKey, group, serviceId);
LOG.info("Subscribe partial config from Redis server, {}={}, serviceId={}", groupKey, group, serviceId);
return new MessageListenerAdapter(configAdapter, "subscribePartialConfig");
}
......
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