|
@@ -0,0 +1,58 @@
|
|
|
|
|
+import com.alibaba.nacos.api.NacosFactory;
|
|
|
|
|
+import com.alibaba.nacos.api.PropertyKeyConst;
|
|
|
|
|
+import com.alibaba.nacos.api.config.ConfigService;
|
|
|
|
|
+import com.alibaba.nacos.api.config.listener.Listener;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.Properties;
|
|
|
|
|
+import java.util.concurrent.Executor;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * @author reghao
|
|
|
|
|
+ * @date 2025-08-04 10:49:44
|
|
|
|
|
+ */
|
|
|
|
|
+public class NacosConfigTest {
|
|
|
|
|
+ public static void main(String[] args) throws Exception {
|
|
|
|
|
+ String serverAddr = "localhost";
|
|
|
|
|
+ String dataId = "search-dev";
|
|
|
|
|
+ String group = "DEFAULT_GROUP";
|
|
|
|
|
+ Properties properties = new Properties();
|
|
|
|
|
+ properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr);
|
|
|
|
|
+ ConfigService configService = NacosFactory.createConfigService(properties);
|
|
|
|
|
+ String content = configService.getConfig(dataId, group, 5000);
|
|
|
|
|
+ System.out.println("############################################################################");
|
|
|
|
|
+ System.out.println(content);
|
|
|
|
|
+ System.out.println("############################################################################");
|
|
|
|
|
+ configService.addListener(dataId, group, new Listener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void receiveConfigInfo(String configInfo) {
|
|
|
|
|
+ System.out.println("receive:" + configInfo);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Executor getExecutor() {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ /*boolean isPublishOk = configService.publishConfig(dataId, group, "content");
|
|
|
|
|
+ System.out.println(isPublishOk);*/
|
|
|
|
|
+
|
|
|
|
|
+ //Thread.sleep(3000);
|
|
|
|
|
+ //content = configService.getConfig(dataId, group, 5000);
|
|
|
|
|
+ System.out.println("############################################################################");
|
|
|
|
|
+ //System.out.println(content);
|
|
|
|
|
+ System.out.println("############################################################################");
|
|
|
|
|
+
|
|
|
|
|
+ /*boolean isRemoveOk = configService.removeConfig(dataId, group);
|
|
|
|
|
+ System.out.println(isRemoveOk);
|
|
|
|
|
+ Thread.sleep(3000);*/
|
|
|
|
|
+
|
|
|
|
|
+ //content = configService.getConfig(dataId, group, 5000);
|
|
|
|
|
+ System.out.println("############################################################################");
|
|
|
|
|
+ //System.out.println(content);
|
|
|
|
|
+ System.out.println("############################################################################");
|
|
|
|
|
+
|
|
|
|
|
+ System.out.println("goto long sleep");
|
|
|
|
|
+ Thread.sleep(300_000);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|