static ThreadPoolExecutor threadPoolExecutor =
new ThreadPoolExecutor(2,4,1,TimeUnit.SECONDS,
new LinkedBlockingDeque<>(100), new ThreadPoolExecutor.CallerRunsPolicy());
public static void main(String[] args) {
// 监听 nacos 对应的一个 dataId 的数据变动
Listener listenerJsonTest = new Listener() {
@Override
public Executor getExecutor() {
return threadPoolExecutor;
}
@Override
public void receiveConfigInfo(String s) {
// 收到变动
System.out.println(s);
}
};
Listener listenerJson2= new Listener() {
@Override
public Executor getExecutor() {
return threadPoolExecutor;
}
@Override
public void receiveConfigInfo(String s) {
}
};
Properties properties = new Properties();
properties.put(PropertyKeyConst.SERVER_ADDR,"localhost:8848");
properties.put(PropertyKeyConst.NAMESPACE, "dev");
ConfigService configService = null;
try {
configService = NacosFactory.createConfigService(properties);
} catch (NacosException e) {
e.printStackTrace();
}
try {
String jsonTestStr = configService.getConfig("json-test", "demo", 1000);
System.out.println(jsonTestStr);
configService.addListener("json-test", "demo", listenerJsonTest);
} catch (NacosException e) {
e.printStackTrace();
}
while (true) {
}
}
网友评论