Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
discovery
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陈文顺
discovery
Commits
661238d1
Commit
661238d1
authored
Jun 24, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改介绍
parent
f3ad0c0d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
25 deletions
+41
-25
README.md
+26
-14
discovery-springcloud-example-a/src/main/java/com/nepxion/discovery/plugin/example/impl/DiscoveryConfigAdapter.java
+15
-11
No files found.
README.md
View file @
661238d1
...
@@ -80,26 +80,38 @@ Nepxion Discovery是一款对Spring Cloud Discovery的服务注册增强插件
...
@@ -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
// return "file:rule.xml";
public
class
DiscoveryConfigLoader
extends
AbstractConfigLoader
{
}
// 通过application.properties里的spring.application.discovery.remote.config.enabled=true,来决定走远程配置中心,还是本地
// 从远程配置中心获取
XML内容
// 从远程配置中心获取
配置
@Override
@Override
public InputStream getRemoteInputStream() {
public InputStream getRemoteInputStream() {
return
null
;
InputStream inputStream = ...;
return inputStream;
}
}
// 从本地获取XML内容
// 订阅远程配置中心的配置更新
@Override
@PostConstruct
protected
String
getLocalContextPath
()
{
public void initialize() {
// 配置文件放在resources目录下
InputStream inputStream = ...;
return
"classpath:rule1.xml"
;
// 配置文件放在工程根目录下
publish(inputStream);
// return "file:rule1.xml";
}
}
}
}
```
```
...
...
discovery-springcloud-example-a/src/main/java/com/nepxion/discovery/plugin/example/impl/DiscoveryConfigAdapter.java
View file @
661238d1
...
@@ -22,11 +22,23 @@ import org.apache.commons.io.FileUtils;
...
@@ -22,11 +22,23 @@ import org.apache.commons.io.FileUtils;
import
com.nepxion.discovery.plugin.configcenter.ConfigAdapter
;
import
com.nepxion.discovery.plugin.configcenter.ConfigAdapter
;
// 模拟从本地配置或远程配置中心获取配置,订阅配置更新
// 模拟主动从本地或远程配置中心获取配置
// 模拟订阅远程配置中心的配置更新
public
class
DiscoveryConfigAdapter
extends
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
@Override
public
InputStream
getRemoteInputStream
()
{
public
InputStream
getRemoteInputStream
()
{
// 本地文件模拟代替远程文件
try
{
try
{
return
FileUtils
.
openInputStream
(
new
File
(
"src/main/resources/rule1.xml"
));
return
FileUtils
.
openInputStream
(
new
File
(
"src/main/resources/rule1.xml"
));
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
...
@@ -36,15 +48,7 @@ public class DiscoveryConfigAdapter extends ConfigAdapter {
...
@@ -36,15 +48,7 @@ public class DiscoveryConfigAdapter extends ConfigAdapter {
return
null
;
return
null
;
}
}
@Override
// 订阅远程配置中心的配置更新
protected
String
getLocalContextPath
()
{
// 配置文件放在resources目录下
return
"classpath:rule1.xml"
;
// 配置文件放在工程根目录下
// return "file:rule1.xml";
}
@PostConstruct
@PostConstruct
public
void
initialize
()
{
public
void
initialize
()
{
ThreadLocalRandom
threadLocalRandom
=
ThreadLocalRandom
.
current
();
ThreadLocalRandom
threadLocalRandom
=
ThreadLocalRandom
.
current
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment