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
22824902
Commit
22824902
authored
Jun 24, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加REST推送方式
parent
7090b666
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
70 additions
and
22 deletions
+70
-22
discovery-plugin-admin-center/src/main/java/com/nepxion/discovery/plugin/admincenter/endpoint/AdminEndpoint.java
+34
-0
discovery-plugin-config-center/pom.xml
+0
-5
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/ConfigSubscriber.java
+16
-1
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/configuration/ConfigAutoConfiguration.java
+0
-7
discovery-plugin-framework/pom.xml
+6
-0
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/configuration/PluginAutoConfiguration.java
+6
-0
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/event/PluginPublisher.java
+5
-6
discovery-springcloud-example-a/src/main/java/com/nepxion/discovery/plugin/example/impl/DiscoveryConfigSubscriber.java
+3
-3
No files found.
discovery-plugin-admin-center/src/main/java/com/nepxion/discovery/plugin/admincenter/endpoint/AdminEndpoint.java
View file @
22824902
...
@@ -9,8 +9,11 @@ package com.nepxion.discovery.plugin.admincenter.endpoint;
...
@@ -9,8 +9,11 @@ package com.nepxion.discovery.plugin.admincenter.endpoint;
* @version 1.0
* @version 1.0
*/
*/
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.Collections
;
import
java.util.Collections
;
import
org.apache.commons.io.IOUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.BeansException
;
...
@@ -33,6 +36,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
...
@@ -33,6 +36,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
import
com.nepxion.discovery.plugin.framework.cache.PluginCache
;
import
com.nepxion.discovery.plugin.framework.cache.PluginCache
;
import
com.nepxion.discovery.plugin.framework.constant.PluginConstant
;
import
com.nepxion.discovery.plugin.framework.constant.PluginConstant
;
import
com.nepxion.discovery.plugin.framework.event.PluginPublisher
;
import
com.nepxion.discovery.plugin.framework.exception.PluginException
;
import
com.nepxion.discovery.plugin.framework.exception.PluginException
;
@ManagedResource
(
description
=
"Admin Endpoint"
)
@ManagedResource
(
description
=
"Admin Endpoint"
)
...
@@ -40,6 +44,8 @@ import com.nepxion.discovery.plugin.framework.exception.PluginException;
...
@@ -40,6 +44,8 @@ import com.nepxion.discovery.plugin.framework.exception.PluginException;
public
class
AdminEndpoint
extends
AbstractMvcEndpoint
implements
ApplicationContextAware
{
public
class
AdminEndpoint
extends
AbstractMvcEndpoint
implements
ApplicationContextAware
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
AdminEndpoint
.
class
);
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
AdminEndpoint
.
class
);
private
static
final
String
ENCODING_UTF_8
=
"UTF-8"
;
private
ConfigurableApplicationContext
applicationContext
;
private
ConfigurableApplicationContext
applicationContext
;
@SuppressWarnings
(
"rawtypes"
)
@SuppressWarnings
(
"rawtypes"
)
private
ServiceRegistry
serviceRegistry
;
private
ServiceRegistry
serviceRegistry
;
...
@@ -48,6 +54,9 @@ public class AdminEndpoint extends AbstractMvcEndpoint implements ApplicationCon
...
@@ -48,6 +54,9 @@ public class AdminEndpoint extends AbstractMvcEndpoint implements ApplicationCon
@Autowired
@Autowired
private
PluginCache
pluginCache
;
private
PluginCache
pluginCache
;
@Autowired
private
PluginPublisher
pluginPublisher
;
@SuppressWarnings
(
"rawtypes"
)
@SuppressWarnings
(
"rawtypes"
)
public
AdminEndpoint
(
ServiceRegistry
serviceRegistry
)
{
public
AdminEndpoint
(
ServiceRegistry
serviceRegistry
)
{
super
(
"/admin"
,
true
,
true
);
super
(
"/admin"
,
true
,
true
);
...
@@ -59,6 +68,31 @@ public class AdminEndpoint extends AbstractMvcEndpoint implements ApplicationCon
...
@@ -59,6 +68,31 @@ public class AdminEndpoint extends AbstractMvcEndpoint implements ApplicationCon
this
.
registration
=
registration
;
this
.
registration
=
registration
;
}
}
@RequestMapping
(
path
=
"config"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
@ManagedOperation
public
Object
config
(
@RequestBody
String
config
)
{
Boolean
discoveryControlEnabled
=
getEnvironment
().
getProperty
(
PluginConstant
.
SPRING_APPLICATION_DISCOVERY_CONTROL_ENABLED
,
Boolean
.
class
,
Boolean
.
TRUE
);
if
(!
discoveryControlEnabled
)
{
return
new
ResponseEntity
<>(
Collections
.
singletonMap
(
"Message"
,
"Discovery control is disabled"
),
HttpStatus
.
NOT_FOUND
);
}
if
(
registration
==
null
)
{
throw
new
PluginException
(
"No registration found"
);
}
try
{
InputStream
inputStream
=
IOUtils
.
toInputStream
(
config
,
ENCODING_UTF_8
);
pluginPublisher
.
publish
(
inputStream
);
}
catch
(
IOException
e
)
{
throw
new
PluginException
(
"To input stream failed"
,
e
);
}
LOG
.
info
(
"receive config successfully"
);
return
"success"
;
}
@RequestMapping
(
path
=
"blacklist"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
path
=
"blacklist"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
@ResponseBody
@ManagedOperation
@ManagedOperation
...
...
discovery-plugin-config-center/pom.xml
View file @
22824902
...
@@ -21,11 +21,6 @@
...
@@ -21,11 +21,6 @@
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
${project.groupId}
</groupId>
<artifactId>
eventbus-aop-starter
</artifactId>
</dependency>
<dependency>
<groupId>
dom4j
</groupId>
<groupId>
dom4j
</groupId>
<artifactId>
dom4j
</artifactId>
<artifactId>
dom4j
</artifactId>
</dependency>
</dependency>
...
...
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/ConfigSubscriber.java
View file @
22824902
...
@@ -24,6 +24,7 @@ import org.springframework.beans.factory.annotation.Value;
...
@@ -24,6 +24,7 @@ import org.springframework.beans.factory.annotation.Value;
import
com.google.common.eventbus.Subscribe
;
import
com.google.common.eventbus.Subscribe
;
import
com.nepxion.discovery.plugin.configcenter.constant.ConfigConstant
;
import
com.nepxion.discovery.plugin.configcenter.constant.ConfigConstant
;
import
com.nepxion.discovery.plugin.configcenter.loader.ConfigLoader
;
import
com.nepxion.discovery.plugin.configcenter.loader.ConfigLoader
;
import
com.nepxion.discovery.plugin.framework.constant.PluginConstant
;
import
com.nepxion.discovery.plugin.framework.exception.PluginException
;
import
com.nepxion.discovery.plugin.framework.exception.PluginException
;
import
com.nepxion.eventbus.annotation.EventBus
;
import
com.nepxion.eventbus.annotation.EventBus
;
import
com.nepxion.eventbus.core.Event
;
import
com.nepxion.eventbus.core.Event
;
...
@@ -32,6 +33,9 @@ import com.nepxion.eventbus.core.Event;
...
@@ -32,6 +33,9 @@ import com.nepxion.eventbus.core.Event;
public
class
ConfigSubscriber
{
public
class
ConfigSubscriber
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
ConfigSubscriber
.
class
);
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
ConfigSubscriber
.
class
);
@Value
(
"${"
+
PluginConstant
.
SPRING_APPLICATION_DISCOVERY_CONTROL_ENABLED
+
":true}"
)
private
Boolean
discoveryControlEnabled
;
@Value
(
"${"
+
ConfigConstant
.
SPRING_APPLICATION_DISCOVERY_REMOTE_CONFIG_ENABLED
+
":true}"
)
@Value
(
"${"
+
ConfigConstant
.
SPRING_APPLICATION_DISCOVERY_REMOTE_CONFIG_ENABLED
+
":true}"
)
private
Boolean
remoteConfigEnabled
;
private
Boolean
remoteConfigEnabled
;
...
@@ -56,15 +60,26 @@ public class ConfigSubscriber {
...
@@ -56,15 +60,26 @@ public class ConfigSubscriber {
@Subscribe
@Subscribe
public
void
subscribe
(
Event
event
)
{
public
void
subscribe
(
Event
event
)
{
if
(!
discoveryControlEnabled
)
{
LOG
.
info
(
"********** Discovery control is disabled, reject to accept remote push **********"
);
return
;
}
if
(!
remoteConfigEnabled
)
{
if
(!
remoteConfigEnabled
)
{
LOG
.
info
(
"********** Remote config is disabled, reject to accept remote push **********"
);
return
;
return
;
}
}
Object
object
=
event
.
getSource
();
if
(
object
instanceof
InputStream
)
{
LOG
.
info
(
"********** Remote config change has been retrieved **********"
);
LOG
.
info
(
"********** Remote config change has been retrieved **********"
);
InputStream
inputStream
=
(
InputStream
)
event
.
getSource
()
;
InputStream
inputStream
=
(
InputStream
)
object
;
parse
(
inputStream
);
parse
(
inputStream
);
}
}
}
private
void
parse
(
InputStream
inputStream
)
{
private
void
parse
(
InputStream
inputStream
)
{
if
(
inputStream
==
null
)
{
if
(
inputStream
==
null
)
{
...
...
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/configuration/ConfigAutoConfiguration.java
View file @
22824902
...
@@ -13,7 +13,6 @@ import org.springframework.context.annotation.Bean;
...
@@ -13,7 +13,6 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
com.nepxion.discovery.plugin.configcenter.ConfigParser
;
import
com.nepxion.discovery.plugin.configcenter.ConfigParser
;
import
com.nepxion.discovery.plugin.configcenter.ConfigPublisher
;
import
com.nepxion.discovery.plugin.configcenter.ConfigSubscriber
;
import
com.nepxion.discovery.plugin.configcenter.ConfigSubscriber
;
@Configuration
@Configuration
...
@@ -27,9 +26,4 @@ public class ConfigAutoConfiguration {
...
@@ -27,9 +26,4 @@ public class ConfigAutoConfiguration {
public
ConfigSubscriber
configSubscriber
()
{
public
ConfigSubscriber
configSubscriber
()
{
return
new
ConfigSubscriber
();
return
new
ConfigSubscriber
();
}
}
@Bean
public
ConfigPublisher
configPublisher
()
{
return
new
ConfigPublisher
();
}
}
}
\ No newline at end of file
discovery-plugin-framework/pom.xml
View file @
22824902
...
@@ -34,5 +34,10 @@
...
@@ -34,5 +34,10 @@
<groupId>
org.springframework.cloud
</groupId>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-eureka
</artifactId>
<artifactId>
spring-cloud-starter-eureka
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
${project.groupId}
</groupId>
<artifactId>
eventbus-aop-starter
</artifactId>
</dependency>
</dependencies>
</dependencies>
</project>
</project>
\ No newline at end of file
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/configuration/PluginAutoConfiguration.java
View file @
22824902
...
@@ -16,6 +16,7 @@ import org.springframework.context.annotation.Configuration;
...
@@ -16,6 +16,7 @@ import org.springframework.context.annotation.Configuration;
import
com.nepxion.discovery.plugin.framework.cache.PluginCache
;
import
com.nepxion.discovery.plugin.framework.cache.PluginCache
;
import
com.nepxion.discovery.plugin.framework.entity.RuleEntity
;
import
com.nepxion.discovery.plugin.framework.entity.RuleEntity
;
import
com.nepxion.discovery.plugin.framework.event.PluginPublisher
;
import
com.nepxion.discovery.plugin.framework.strategy.DiscoveryControlStrategy
;
import
com.nepxion.discovery.plugin.framework.strategy.DiscoveryControlStrategy
;
import
com.nepxion.discovery.plugin.framework.strategy.RegisterControlStrategy
;
import
com.nepxion.discovery.plugin.framework.strategy.RegisterControlStrategy
;
...
@@ -32,6 +33,11 @@ public class PluginAutoConfiguration {
...
@@ -32,6 +33,11 @@ public class PluginAutoConfiguration {
}
}
@Bean
@Bean
public
PluginPublisher
pluginPublisher
()
{
return
new
PluginPublisher
();
}
@Bean
public
ReentrantReadWriteLock
reentrantReadWriteLock
()
{
public
ReentrantReadWriteLock
reentrantReadWriteLock
()
{
return
new
ReentrantReadWriteLock
();
return
new
ReentrantReadWriteLock
();
}
}
...
...
discovery-plugin-
config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/Config
Publisher.java
→
discovery-plugin-
framework/src/main/java/com/nepxion/discovery/plugin/framework/event/Plugin
Publisher.java
View file @
22824902
package
com
.
nepxion
.
discovery
.
plugin
.
configcenter
;
package
com
.
nepxion
.
discovery
.
plugin
.
framework
.
event
;
/**
/**
* <p>Title: Nepxion Discovery</p>
* <p>Title: Nepxion Discovery</p>
...
@@ -9,18 +9,16 @@ package com.nepxion.discovery.plugin.configcenter;
...
@@ -9,18 +9,16 @@ package com.nepxion.discovery.plugin.configcenter;
* @version 1.0
* @version 1.0
*/
*/
import
java.io.InputStream
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
com.nepxion.eventbus.core.Event
;
import
com.nepxion.eventbus.core.Event
;
import
com.nepxion.eventbus.core.EventControllerFactory
;
import
com.nepxion.eventbus.core.EventControllerFactory
;
public
class
Config
Publisher
{
public
class
Plugin
Publisher
{
@Autowired
@Autowired
private
EventControllerFactory
eventControllerFactory
;
private
EventControllerFactory
eventControllerFactory
;
public
void
publish
(
InputStream
inputStream
)
{
public
void
publish
(
Object
object
)
{
eventControllerFactory
.
getAsyncController
().
post
(
new
Event
(
inputStream
));
eventControllerFactory
.
getAsyncController
().
post
(
new
Event
(
object
));
}
}
}
}
\ No newline at end of file
discovery-springcloud-example-a/src/main/java/com/nepxion/discovery/plugin/example/impl/DiscoveryConfigSubscriber.java
View file @
22824902
...
@@ -21,12 +21,12 @@ import javax.annotation.PostConstruct;
...
@@ -21,12 +21,12 @@ import javax.annotation.PostConstruct;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
com.nepxion.discovery.plugin.
configcenter.Config
Publisher
;
import
com.nepxion.discovery.plugin.
framework.event.Plugin
Publisher
;
// 模拟从远程配置中心接受配置更新
// 模拟从远程配置中心接受配置更新
public
class
DiscoveryConfigSubscriber
{
public
class
DiscoveryConfigSubscriber
{
@Autowired
@Autowired
private
ConfigPublisher
config
Publisher
;
private
PluginPublisher
plugin
Publisher
;
@PostConstruct
@PostConstruct
public
void
initialize
()
{
public
void
initialize
()
{
...
@@ -40,7 +40,7 @@ public class DiscoveryConfigSubscriber {
...
@@ -40,7 +40,7 @@ public class DiscoveryConfigSubscriber {
int
index
=
threadLocalRandom
.
nextInt
(
5
)
+
1
;
int
index
=
threadLocalRandom
.
nextInt
(
5
)
+
1
;
System
.
out
.
println
(
"-------------------- rule"
+
index
+
".xml is loaded --------------------"
);
System
.
out
.
println
(
"-------------------- rule"
+
index
+
".xml is loaded --------------------"
);
InputStream
inputStream
=
getInputStream
(
"src/main/resources/rule"
+
index
+
".xml"
);
InputStream
inputStream
=
getInputStream
(
"src/main/resources/rule"
+
index
+
".xml"
);
config
Publisher
.
publish
(
inputStream
);
plugin
Publisher
.
publish
(
inputStream
);
}
}
},
10000L
,
15000L
);
},
10000L
,
15000L
);
}
}
...
...
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