提交 70cc0b8e 编写于 作者: H huangjian888 提交者: Liang Zhang

Nacos RegistryCenter Added Namespace Property Configuration (#3209)

* Nacos RegistryCenter Added Namespace Property Configuration

* For checkstyle
上级 68b1bf67
...@@ -35,7 +35,7 @@ import java.util.Properties; ...@@ -35,7 +35,7 @@ import java.util.Properties;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
@Slf4j @Slf4j
public class NacosRegistryCenter implements RegistryCenter { public final class NacosRegistryCenter implements RegistryCenter {
private ConfigService configService; private ConfigService configService;
...@@ -46,9 +46,12 @@ public class NacosRegistryCenter implements RegistryCenter { ...@@ -46,9 +46,12 @@ public class NacosRegistryCenter implements RegistryCenter {
@Override @Override
public void init(final RegistryCenterConfiguration config) { public void init(final RegistryCenterConfiguration config) {
try { try {
configService = NacosFactory.createConfigService(config.getServerLists()); Properties properties = new Properties();
} catch (NacosException e) { properties.put("serverAddr", config.getServerLists());
log.debug("exception for: {}", e.toString()); properties.put("namespace", null == config.getNamespace() ? "" : config.getNamespace());
configService = NacosFactory.createConfigService(properties);
} catch (final NacosException ex) {
log.debug("exception for: {}", ex.toString());
} }
} }
...@@ -64,8 +67,8 @@ public class NacosRegistryCenter implements RegistryCenter { ...@@ -64,8 +67,8 @@ public class NacosRegistryCenter implements RegistryCenter {
String group = properties.getProperty("group", "SHARDING_SPHERE_DEFAULT_GROUP"); String group = properties.getProperty("group", "SHARDING_SPHERE_DEFAULT_GROUP");
long timeoutMs = Long.parseLong(properties.getProperty("timeout", "3000")); long timeoutMs = Long.parseLong(properties.getProperty("timeout", "3000"));
return configService.getConfig(dataId, group, timeoutMs); return configService.getConfig(dataId, group, timeoutMs);
} catch (NacosException e) { } catch (final NacosException ex) {
log.debug("exception for: {}", e.toString()); log.debug("exception for: {}", ex.toString());
return null; return null;
} }
} }
...@@ -91,8 +94,8 @@ public class NacosRegistryCenter implements RegistryCenter { ...@@ -91,8 +94,8 @@ public class NacosRegistryCenter implements RegistryCenter {
String dataId = key.replace("/", "."); String dataId = key.replace("/", ".");
String group = properties.getProperty("group", "SHARDING_SPHERE_DEFAULT_GROUP"); String group = properties.getProperty("group", "SHARDING_SPHERE_DEFAULT_GROUP");
configService.publishConfig(dataId, group, value); configService.publishConfig(dataId, group, value);
} catch (NacosException e) { } catch (final NacosException ex) {
log.debug("exception for: {}", e.toString()); log.debug("exception for: {}", ex.toString());
} }
} }
...@@ -118,8 +121,8 @@ public class NacosRegistryCenter implements RegistryCenter { ...@@ -118,8 +121,8 @@ public class NacosRegistryCenter implements RegistryCenter {
dataChangedEventListener.onChange(new DataChangedEvent(key, configInfo, DataChangedEvent.ChangedType.UPDATED)); dataChangedEventListener.onChange(new DataChangedEvent(key, configInfo, DataChangedEvent.ChangedType.UPDATED));
} }
}); });
} catch (NacosException e) { } catch (final NacosException ex) {
log.debug("exception for: {}", e.toString()); log.debug("exception for: {}", ex.toString());
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册