use of org.apache.dubbo.common.config.configcenter.DynamicConfiguration in project dubbo by alibaba.
the class DynamicConfigurationServiceNameMapping method getAndListen.
@Override
public Set<String> getAndListen(URL url, MappingListener mappingListener) {
String serviceInterface = url.getServiceInterface();
DynamicConfiguration dynamicConfiguration = DynamicConfiguration.getDynamicConfiguration();
Set<String> serviceNames = new LinkedHashSet<>();
execute(() -> {
Set<String> keys = dynamicConfiguration.getConfigKeys(ServiceNameMapping.buildGroup(serviceInterface));
if (CollectionUtils.isNotEmpty(keys)) {
serviceNames.addAll(keys);
}
});
return Collections.unmodifiableSet(serviceNames);
}
use of org.apache.dubbo.common.config.configcenter.DynamicConfiguration in project dubbo by alibaba.
the class DynamicConfigurationServiceNameMapping method map.
@Override
public void map(URL url) {
String serviceInterface = url.getServiceInterface();
String group = url.getParameter(GROUP_KEY);
if (IGNORED_SERVICE_INTERFACES.contains(serviceInterface)) {
return;
}
DynamicConfiguration dynamicConfiguration = DynamicConfiguration.getDynamicConfiguration();
// the Dubbo Service Key as group
// the service(application) name as key
// It does matter whatever the content is, we just need a record
String key = getName();
String content = valueOf(System.currentTimeMillis());
execute(() -> {
dynamicConfiguration.publishConfig(key, ServiceNameMapping.buildGroup(serviceInterface), content);
if (logger.isInfoEnabled()) {
logger.info(String.format("Dubbo service[%s] mapped to interface name[%s].", group, serviceInterface));
}
});
}
use of org.apache.dubbo.common.config.configcenter.DynamicConfiguration in project dubbo by alibaba.
the class DubboBootstrap method prepareEnvironment.
/* serve for builder apis, end */
private DynamicConfiguration prepareEnvironment(ConfigCenterConfig configCenter) {
if (configCenter.isValid()) {
if (!configCenter.checkOrUpdateInited()) {
return null;
}
DynamicConfiguration dynamicConfiguration = getDynamicConfiguration(configCenter.toUrl());
String configContent = dynamicConfiguration.getProperties(configCenter.getConfigFile(), configCenter.getGroup());
String appGroup = getApplication().getName();
String appConfigContent = null;
if (isNotEmpty(appGroup)) {
appConfigContent = dynamicConfiguration.getProperties(isNotEmpty(configCenter.getAppConfigFile()) ? configCenter.getAppConfigFile() : configCenter.getConfigFile(), appGroup);
}
try {
environment.setConfigCenterFirst(configCenter.isHighestPriority());
Map<String, String> globalRemoteProperties = parseProperties(configContent);
if (CollectionUtils.isEmptyMap(globalRemoteProperties)) {
logger.info("No global configuration in config center");
}
environment.updateExternalConfigurationMap(globalRemoteProperties);
Map<String, String> appRemoteProperties = parseProperties(appConfigContent);
if (CollectionUtils.isEmptyMap(appRemoteProperties)) {
logger.info("No application level configuration in config center");
}
environment.updateAppExternalConfigurationMap(appRemoteProperties);
} catch (IOException e) {
throw new IllegalStateException("Failed to parse configurations from Config Center.", e);
}
return dynamicConfiguration;
}
return null;
}
Aggregations