From 3d7ffe0c5263c09b0a715f8ac9ea6346a672dda5 Mon Sep 17 00:00:00 2001 From: eson Date: Mon, 13 Jun 2022 17:56:02 +0800 Subject: [PATCH] =?UTF-8?q?TODO:=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yuandian/dataflow/config/Config.java | 50 ++++++++++++++++++- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/yuandian/dataflow/config/Config.java b/src/main/java/com/yuandian/dataflow/config/Config.java index 40957b5..7f2fab1 100644 --- a/src/main/java/com/yuandian/dataflow/config/Config.java +++ b/src/main/java/com/yuandian/dataflow/config/Config.java @@ -29,8 +29,54 @@ import com.google.api.client.http.InputStreamContent; */ public class Config { - private static Config cnf = new Config(); - public static Config GetConfig() { + private Config() throws NacosException, IOException { + String serverAddr = "192.168.1.113:8848"; + String dataId = "dataflow"; + String group = "yuandian"; + + + + Properties properties = new Properties(); + properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr); + ConfigService configService = NacosFactory.createConfigService(properties); + String content = configService.getConfig(dataId, group, 5000); + + + + Prop.load(new StringReader(content)); + + System.out.println(cnf); + + configService.addListener(dataId, group, new Listener() { + @Override + public void receiveConfigInfo(String configInfo) { + System.out.println("recieve:" + configInfo); + try { + Prop.load(new StringReader(configInfo)); + System.out.println(cnf); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public Executor getExecutor() { + return null; + } + }); + } + + public Properties Prop ; + + private static Config cnf ; + public Config(Properties prop) { + Prop = prop; + } + + public static Config GetConfig() throws NacosException, IOException { + if(cnf == null) { + cnf = new Config(); + } return cnf; }