use of com.alibaba.nacos.api.config.listener.Listener in project hummer-framework by hummer-team.
the class NaCosConfig method registerConfigListener.
public void registerConfigListener(boolean addListener) throws NacosException {
NacosConfigParams params = createNacosConfigParams();
if (params == null) {
return;
}
// nacos server instance
ConfigService configService = NacosFactory.createConfigService(params.getProperties());
for (int i = 0; i < params.getGroupIdList().size(); i++) {
String groupId = params.getGroupIdList().get(i);
String dataId = i <= params.getDataIdList().size() ? params.getDataIdList().get(i) : null;
String configType = params.getConfigTypes().get(i);
if (Strings.isNullOrEmpty(groupId) || Strings.isNullOrEmpty(dataId)) {
continue;
}
if (addListener) {
configService.addListener(dataId, groupId, new Listener() {
@Override
public Executor getExecutor() {
return null;
}
@Override
public void receiveConfigInfo(String configInfo) {
handleConfigChange(groupId, dataId, configType, configInfo);
}
});
}
String value = configService.getConfig(dataId, groupId, 3000);
if (!Strings.isNullOrEmpty(value)) {
handleConfigLoad(groupId, dataId, configType, value);
}
}
// 客户端配置上传至服务端
uploadConfig();
}
use of com.alibaba.nacos.api.config.listener.Listener in project anyline by anylineorg.
the class NacosUtil method config.
public String config(String group, String data, final Class<? extends AnylineConfig> T) throws NacosException {
if (BasicUtil.isEmpty(group)) {
group = config.GROUP;
}
log.warn("[nacos config][group:{}][data:{}][class:{}]", group, data, T.getName());
final String gp = group;
final String dt = data;
Listener listener = new Listener() {
@Override
public void receiveConfigInfo(String content) {
log.warn("[nacos reload config][group:{}][data:{}][class:{}]", gp, dt, T.getName());
parse(T, content);
}
@Override
public Executor getExecutor() {
return null;
}
};
String config = config(group, data, listener);
parse(T, config);
return config;
}
use of com.alibaba.nacos.api.config.listener.Listener in project matecloud by matevip.
the class DynamicRouteInit method initRoute.
@PostConstruct
public void initRoute() {
try {
Properties properties = new Properties();
properties.put(PropertyKeyConst.SERVER_ADDR, nacosProperties.getServerAddr());
properties.put(PropertyKeyConst.USERNAME, nacosProperties.getUsername());
properties.put(PropertyKeyConst.PASSWORD, nacosProperties.getPassword());
properties.put(PropertyKeyConst.NAMESPACE, nacosProperties.getNamespace());
ConfigService configService = NacosFactory.createConfigService(properties);
String content = configService.getConfig(MateConstant.CONFIG_DATA_ID_DYNAMIC_ROUTES, nacosProperties.getGroup(), MateConstant.CONFIG_TIMEOUT_MS);
log.info("初始化网关路由开始");
updateRoute(content);
log.info("初始化网关路由完成");
// 开户监听,实现动态
configService.addListener(MateConstant.CONFIG_DATA_ID_DYNAMIC_ROUTES, nacosProperties.getGroup(), new Listener() {
@Override
public void receiveConfigInfo(String configInfo) {
log.info("更新网关路由开始");
updateRoute(configInfo);
log.info("更新网关路由完成");
}
@Override
public Executor getExecutor() {
return null;
}
});
} catch (NacosException e) {
log.error("加载路由出错:{}", e.getErrMsg());
}
}
use of com.alibaba.nacos.api.config.listener.Listener in project wakaka by Crysmart.
the class NacosServerApplication method withListener.
public static void withListener() throws Exception {
Properties properties = new Properties();
properties.put(PropertyKeyConst.SERVER_ADDR, "localhost:8848");
properties.put(PropertyKeyConst.NAMESPACE, "bc8f6500-589a-4a46-a579-a5880a383300");
ConfigService configService = NacosFactory.createConfigService(properties);
configService.addListener("test.yml", "DEFAULT_GROUP", new Listener() {
@Override
public Executor getExecutor() {
System.out.println("getExecutor");
return null;
}
@Override
public void receiveConfigInfo(String configInfo) {
System.out.println(configInfo);
}
});
while (true) {
Thread.sleep(1111l);
System.out.println("==");
}
}
use of com.alibaba.nacos.api.config.listener.Listener in project dynamic-threadpool by acmenlt.
the class NacosRefresherHandler method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws Exception {
Map<String, String> nacosConfig = bootstrapCoreProperties.getNacos();
configService.addListener(nacosConfig.get("data-id"), nacosConfig.get("group"), new Listener() {
@Override
public Executor getExecutor() {
return dynamicRefreshExecutorService;
}
@Override
public void receiveConfigInfo(String configInfo) {
dynamicRefresh(configInfo);
}
});
}
Aggregations