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
f454e0b2
Commit
f454e0b2
authored
Jun 24, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改测试用例
parent
fa229594
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
26 deletions
+18
-26
discovery-springcloud-example-a/src/main/java/com/nepxion/discovery/plugin/example/impl/DiscoveryConfigLoader.java
+10
-14
discovery-springcloud-example-a/src/main/java/com/nepxion/discovery/plugin/example/impl/DiscoveryConfigSubscriber.java
+8
-12
No files found.
discovery-springcloud-example-a/src/main/java/com/nepxion/discovery/plugin/example/impl/DiscoveryConfigLoader.java
View file @
f454e0b2
...
...
@@ -10,10 +10,11 @@ package com.nepxion.discovery.plugin.example.impl;
*/
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
org.apache.commons.io.FileUtils
;
import
com.nepxion.discovery.plugin.configcenter.loader.AbstractConfigLoader
;
// 模拟从本地配置或远程配置中心获取配置
...
...
@@ -21,7 +22,13 @@ public class DiscoveryConfigLoader extends AbstractConfigLoader {
@Override
public
InputStream
getRemoteInputStream
()
{
// 本地文件模拟代替远程文件
return
getInputStream
(
"src/main/resources/rule1.xml"
);
try
{
return
FileUtils
.
openInputStream
(
new
File
(
"src/main/resources/rule1.xml"
));
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
@Override
...
...
@@ -32,14 +39,4 @@ public class DiscoveryConfigLoader extends AbstractConfigLoader {
// 配置文件放在工程根目录下
// return "file:rule1.xml";
}
private
InputStream
getInputStream
(
String
fileName
)
{
try
{
return
new
FileInputStream
(
new
File
(
fileName
));
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
}
\ No newline at end of file
discovery-springcloud-example-a/src/main/java/com/nepxion/discovery/plugin/example/impl/DiscoveryConfigSubscriber.java
View file @
f454e0b2
...
...
@@ -10,8 +10,7 @@ package com.nepxion.discovery.plugin.example.impl;
*/
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.Timer
;
import
java.util.TimerTask
;
...
...
@@ -19,6 +18,7 @@ import java.util.concurrent.ThreadLocalRandom;
import
javax.annotation.PostConstruct
;
import
org.apache.commons.io.FileUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
com.nepxion.discovery.plugin.framework.event.PluginPublisher
;
...
...
@@ -39,19 +39,14 @@ public class DiscoveryConfigSubscriber {
// 本地文件模拟代替远程文件,随机读取
int
index
=
threadLocalRandom
.
nextInt
(
5
)
+
1
;
System
.
out
.
println
(
"-------------------- rule"
+
index
+
".xml is loaded --------------------"
);
InputStream
inputStream
=
getInputStream
(
"src/main/resources/rule"
+
index
+
".xml"
);
pluginPublisher
.
publish
(
inputStream
);
}
},
10000L
,
15000L
);
}
private
InputStream
getInputStream
(
String
fileName
)
{
try
{
return
new
FileInputStream
(
new
File
(
fileName
));
}
catch
(
FileNotFoundException
e
)
{
InputStream
inputStream
=
FileUtils
.
openInputStream
(
new
File
(
"src/main/resources/rule"
+
index
+
".xml"
));
pluginPublisher
.
publish
(
inputStream
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
},
10000L
,
15000L
);
}
}
\ No newline at end of file
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