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
eb7fb816
Commit
eb7fb816
authored
Jun 22, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改测试用例
parent
0ca447f3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
31 deletions
+69
-31
discovery-springcloud-example-a/src/main/java/com/nepxion/discovery/plugin/example/DiscoveryPluginApplication.java
+15
-0
discovery-springcloud-example-a/src/main/java/com/nepxion/discovery/plugin/example/impl/DiscoveryPluginConfigSimulator.java
+5
-31
discovery-springcloud-example-a/src/main/java/com/nepxion/discovery/plugin/example/impl/DiscoveryPluginFileLoader.java
+49
-0
No files found.
discovery-springcloud-example-a/src/main/java/com/nepxion/discovery/plugin/example/DiscoveryPluginApplication.java
View file @
eb7fb816
...
@@ -12,6 +12,10 @@ package com.nepxion.discovery.plugin.example;
...
@@ -12,6 +12,10 @@ package com.nepxion.discovery.plugin.example;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.cloud.client.discovery.EnableDiscoveryClient
;
import
org.springframework.cloud.client.discovery.EnableDiscoveryClient
;
import
org.springframework.context.annotation.Bean
;
import
com.nepxion.discovery.plugin.example.impl.DiscoveryPluginConfigSimulator
;
import
com.nepxion.discovery.plugin.example.impl.DiscoveryPluginFileLoader
;
@SpringBootApplication
@SpringBootApplication
@EnableDiscoveryClient
@EnableDiscoveryClient
...
@@ -19,4 +23,14 @@ public class DiscoveryPluginApplication {
...
@@ -19,4 +23,14 @@ public class DiscoveryPluginApplication {
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
new
SpringApplicationBuilder
(
DiscoveryPluginApplication
.
class
).
web
(
true
).
run
(
args
);
new
SpringApplicationBuilder
(
DiscoveryPluginApplication
.
class
).
web
(
true
).
run
(
args
);
}
}
@Bean
public
DiscoveryPluginFileLoader
discoveryPluginFileLoader
()
{
return
new
DiscoveryPluginFileLoader
();
}
@Bean
public
DiscoveryPluginConfigSimulator
discoveryPluginConfigSimulator
()
{
return
new
DiscoveryPluginConfigSimulator
();
}
}
}
\ No newline at end of file
discovery-springcloud-example-a/src/main/java/com/nepxion/discovery/plugin/example/
DiscoveryPlugin
Simulator.java
→
discovery-springcloud-example-a/src/main/java/com/nepxion/discovery/plugin/example/
impl/DiscoveryPluginConfig
Simulator.java
View file @
eb7fb816
package
com
.
nepxion
.
discovery
.
plugin
.
example
;
package
com
.
nepxion
.
discovery
.
plugin
.
example
.
impl
;
/**
/**
* <p>Title: Nepxion Discovery</p>
* <p>Title: Nepxion Discovery</p>
...
@@ -12,7 +12,6 @@ package com.nepxion.discovery.plugin.example;
...
@@ -12,7 +12,6 @@ package com.nepxion.discovery.plugin.example;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.util.Timer
;
import
java.util.Timer
;
import
java.util.TimerTask
;
import
java.util.TimerTask
;
...
@@ -21,37 +20,11 @@ import java.util.concurrent.ThreadLocalRandom;
...
@@ -21,37 +20,11 @@ import java.util.concurrent.ThreadLocalRandom;
import
javax.annotation.PostConstruct
;
import
javax.annotation.PostConstruct
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.stereotype.Component
;
import
com.nepxion.discovery.plugin.config.DiscoveryPluginConfigPublisher
;
import
com.nepxion.discovery.plugin.config.DiscoveryPluginConfigPublisher
;
import
com.nepxion.discovery.plugin.loader.AbstractFileLoader
;
import
com.nepxion.discovery.plugin.loader.FileLoader
;
@Component
// 模拟从远程配置中心接受配置更新
public
class
DiscoveryPluginSimulator
{
public
class
DiscoveryPluginConfigSimulator
{
// 模拟从本地配置和远程配置获取discovery.xml
@Bean
public
FileLoader
fileLoader
()
{
return
new
AbstractFileLoader
()
{
@Override
public
InputStream
getRemoteInputStream
()
throws
IOException
{
// 本地文件模拟代替远程文件
return
createInputStream
(
"src/main/resources/discovery1.xml"
);
}
@Override
protected
String
getLocalContextPath
()
{
// 配置文件放在resources目录下
return
"classpath:discovery1.xml"
;
// 配置文件放在工程根目录下
// return "file:discovery.xml";
}
};
}
// 模拟每隔15秒通过事件总线接收远程配置中心推送过来的配置更新
@Autowired
@Autowired
private
DiscoveryPluginConfigPublisher
discoveryPluginConfigPublisher
;
private
DiscoveryPluginConfigPublisher
discoveryPluginConfigPublisher
;
...
@@ -59,11 +32,12 @@ public class DiscoveryPluginSimulator {
...
@@ -59,11 +32,12 @@ public class DiscoveryPluginSimulator {
public
void
initialize
()
{
public
void
initialize
()
{
ThreadLocalRandom
threadLocalRandom
=
ThreadLocalRandom
.
current
();
ThreadLocalRandom
threadLocalRandom
=
ThreadLocalRandom
.
current
();
// 模拟每隔15秒通过EventBus接收远程配置中心推送过来的配置更新
Timer
timer
=
new
Timer
();
Timer
timer
=
new
Timer
();
timer
.
scheduleAtFixedRate
(
new
TimerTask
()
{
timer
.
scheduleAtFixedRate
(
new
TimerTask
()
{
public
void
run
()
{
public
void
run
()
{
// 本地文件模拟代替远程文件,随机读取
// 本地文件模拟代替远程文件,随机读取
int
index
=
threadLocalRandom
.
nextInt
(
3
)
+
1
;
int
index
=
threadLocalRandom
.
nextInt
(
4
)
+
1
;
InputStream
inputStream
=
createInputStream
(
"src/main/resources/discovery"
+
index
+
".xml"
);
InputStream
inputStream
=
createInputStream
(
"src/main/resources/discovery"
+
index
+
".xml"
);
discoveryPluginConfigPublisher
.
publish
(
inputStream
);
discoveryPluginConfigPublisher
.
publish
(
inputStream
);
}
}
...
...
discovery-springcloud-example-a/src/main/java/com/nepxion/discovery/plugin/example/impl/DiscoveryPluginFileLoader.java
0 → 100644
View file @
eb7fb816
package
com
.
nepxion
.
discovery
.
plugin
.
example
.
impl
;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
com.nepxion.discovery.plugin.loader.AbstractFileLoader
;
// 模拟从本地配置或远程配置中心获取配置
public
class
DiscoveryPluginFileLoader
extends
AbstractFileLoader
{
@Override
public
InputStream
getRemoteInputStream
()
throws
IOException
{
// 本地文件模拟代替远程文件
return
createInputStream
(
"src/main/resources/discovery1.xml"
);
}
@Override
protected
String
getLocalContextPath
()
{
// 配置文件放在resources目录下
return
"classpath:discovery1.xml"
;
// 配置文件放在工程根目录下
// return "file:discovery.xml";
}
private
InputStream
createInputStream
(
String
fileName
)
{
File
file
=
new
File
(
fileName
);
InputStream
inputStream
=
null
;
try
{
inputStream
=
new
FileInputStream
(
file
);
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
}
return
inputStream
;
}
}
\ 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