use of com.alibaba.nacos.api.config.listener.Listener in project blog_demos by zq2599.
the class RouteConfigListener method dynamicRouteByNacosListener.
@PostConstruct
public void dynamicRouteByNacosListener() throws NacosException {
ConfigService configService = NacosFactory.createConfigService(serverAddr);
// 添加监听,nacos上的配置变更后会执行
configService.addListener(dataId, group, new Listener() {
public void receiveConfigInfo(String configInfo) {
// 解析和处理都交给RouteOperator完成
routeOperator.refreshAll(configInfo);
}
public Executor getExecutor() {
return null;
}
});
// 获取当前的配置
String initConfig = configService.getConfig(dataId, group, 5000);
// 立即更新
routeOperator.refreshAll(initConfig);
}
use of com.alibaba.nacos.api.config.listener.Listener in project incubator-shenyu by apache.
the class NacosServerRegisterRepository method subscribeMetadata.
private void subscribeMetadata(final String serviceConfigName) {
registerMetadata(readData(serviceConfigName));
LOGGER.info("subscribe metadata: {}", serviceConfigName);
try {
configService.addListener(serviceConfigName, defaultGroup, new Listener() {
@Override
public Executor getExecutor() {
return null;
}
@Override
public void receiveConfigInfo(final String config) {
registerMetadata(config);
}
});
} catch (NacosException e) {
throw new ShenyuException(e);
}
}
use of com.alibaba.nacos.api.config.listener.Listener in project hippo4j by longtai-cn.
the class NacosCloudRefresherHandler method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws Exception {
Map<String, String> nacosConfig = bootstrapCoreProperties.getNacos();
nacosConfigManager.getConfigService().addListener(nacosConfig.get("data-id"), nacosConfig.get("group"), new Listener() {
@Override
public Executor getExecutor() {
return dynamicRefreshExecutorService;
}
@Override
public void receiveConfigInfo(String configInfo) {
dynamicRefresh(configInfo);
}
});
}
use of com.alibaba.nacos.api.config.listener.Listener in project hippo4j by longtai-cn.
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);
}
});
}
use of com.alibaba.nacos.api.config.listener.Listener in project hummer-framework by hummer-team.
the class ConfigTest method main.
public static void main(String[] args) throws NacosException, IOException {
String serverAddr = "http://192.168.38.148:8848";
String dataId = "mytest_01";
String group = "test_01";
Properties properties = new Properties();
properties.put("serverAddr", serverAddr);
ConfigService configService = NacosFactory.createConfigService(properties);
String content = configService.getConfig(dataId, group, 5000);
System.out.println(content);
configService.addListener("data_01", "G_1", new Listener() {
@Override
public Executor getExecutor() {
return null;
}
@Override
public void receiveConfigInfo(String configInfo) {
System.out.println("recieve22:" + configInfo);
}
});
configService.addListener(dataId, group, new Listener() {
@Override
public void receiveConfigInfo(String configInfo) {
System.out.println("recieve:" + configInfo);
}
@Override
public Executor getExecutor() {
return null;
}
});
System.in.read();
}
Aggregations