Commit 661238d1 by Nepxion

修改介绍

parent f3ad0c0d
......@@ -80,26 +80,38 @@ Nepxion Discovery是一款对Spring Cloud Discovery的服务注册增强插件
```
## 跟远程配置中心整合
使用者可以跟携程Apollo,百度DisConf等远程配置中心整合
使用者可以跟携程Apollo,百度DisConf等远程配置中心整合,需要实现两个功能
```xml
1. 主动从本地或远程配置中心获取配置
2. 订阅远程配置中心的配置更新
```
继承ConfigAdapter.java
public class DiscoveryConfigAdapter extends ConfigAdapter {
// 通过application.properties里的spring.application.discovery.remote.config.enabled=true,来决定主动从本地,还是远程配置中心获取配置
// 从本地获取配置
@Override
protected String getLocalContextPath() {
// 配置文件放在resources目录下
return "classpath:rule.xml";
继承AbstractConfigLoader.java,实现配置文件获取的对接
```java
public class DiscoveryConfigLoader extends AbstractConfigLoader {
// 通过application.properties里的spring.application.discovery.remote.config.enabled=true,来决定走远程配置中心,还是本地
// 从远程配置中心获取XML内容
// 配置文件放在工程根目录下
// return "file:rule.xml";
}
// 从远程配置中心获取配置
@Override
public InputStream getRemoteInputStream() {
return null;
InputStream inputStream = ...;
return inputStream;
}
// 从本地获取XML内容
@Override
protected String getLocalContextPath() {
// 配置文件放在resources目录下
return "classpath:rule1.xml";
// 订阅远程配置中心的配置更新
@PostConstruct
public void initialize() {
InputStream inputStream = ...;
// 配置文件放在工程根目录下
// return "file:rule1.xml";
publish(inputStream);
}
}
```
......
......@@ -22,11 +22,23 @@ import org.apache.commons.io.FileUtils;
import com.nepxion.discovery.plugin.configcenter.ConfigAdapter;
// 模拟从本地配置或远程配置中心获取配置,订阅配置更新
// 模拟主动从本地或远程配置中心获取配置
// 模拟订阅远程配置中心的配置更新
public class DiscoveryConfigAdapter extends ConfigAdapter {
// 通过application.properties里的spring.application.discovery.remote.config.enabled=true,来决定主动从本地,还是远程配置中心获取配置
// 从本地获取配置
@Override
protected String getLocalContextPath() {
// 配置文件放在resources目录下
return "classpath:rule1.xml";
// 配置文件放在工程根目录下
// return "file:rule1.xml";
}
// 从远程配置中心获取配置
@Override
public InputStream getRemoteInputStream() {
// 本地文件模拟代替远程文件
try {
return FileUtils.openInputStream(new File("src/main/resources/rule1.xml"));
} catch (IOException e) {
......@@ -36,15 +48,7 @@ public class DiscoveryConfigAdapter extends ConfigAdapter {
return null;
}
@Override
protected String getLocalContextPath() {
// 配置文件放在resources目录下
return "classpath:rule1.xml";
// 配置文件放在工程根目录下
// return "file:rule1.xml";
}
// 订阅远程配置中心的配置更新
@PostConstruct
public void initialize() {
ThreadLocalRandom threadLocalRandom = ThreadLocalRandom.current();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment