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
4c7291cf
Commit
4c7291cf
authored
Jul 27, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增用户自定义和编程灰度路由策略
parent
aaa57beb
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
36 additions
and
3 deletions
+36
-3
discovery-springcloud-example/pom.xml
+6
-0
discovery-springcloud-example/src/main/java/com/nepxion/discovery/plugin/example/DiscoveryApplicationA1.java
+7
-0
discovery-springcloud-example/src/main/java/com/nepxion/discovery/plugin/example/feign/AFeignImpl.java
+5
-1
discovery-springcloud-example/src/main/java/com/nepxion/discovery/plugin/example/feign/BFeignImpl.java
+5
-1
discovery-springcloud-example/src/main/java/com/nepxion/discovery/plugin/example/feign/CFeignImpl.java
+5
-1
discovery-springcloud-example/src/main/resources/bootstrap.properties
+8
-0
No files found.
discovery-springcloud-example/pom.xml
View file @
4c7291cf
...
@@ -46,6 +46,12 @@
...
@@ -46,6 +46,12 @@
<dependency>
<dependency>
<groupId>
com.nepxion
</groupId>
<groupId>
com.nepxion
</groupId>
<artifactId>
discovery-plugin-strategy-extension-service
</artifactId>
<version>
${discovery.plugin.version}
</version>
</dependency>
<dependency>
<groupId>
com.nepxion
</groupId>
<artifactId>
discovery-plugin-config-center-extension-nacos
</artifactId>
<artifactId>
discovery-plugin-config-center-extension-nacos
</artifactId>
<version>
${discovery.plugin.version}
</version>
<version>
${discovery.plugin.version}
</version>
</dependency>
</dependency>
...
...
discovery-springcloud-example/src/main/java/com/nepxion/discovery/plugin/example/DiscoveryApplicationA1.java
View file @
4c7291cf
...
@@ -15,6 +15,7 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
...
@@ -15,6 +15,7 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import
org.springframework.cloud.openfeign.EnableFeignClients
;
import
org.springframework.cloud.openfeign.EnableFeignClients
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
com.nepxion.discovery.plugin.example.extension.MyDiscoveryEnabledAdapter
;
import
com.nepxion.discovery.plugin.example.extension.MyDiscoveryListener
;
import
com.nepxion.discovery.plugin.example.extension.MyDiscoveryListener
;
import
com.nepxion.discovery.plugin.example.extension.MyLoadBalanceListener
;
import
com.nepxion.discovery.plugin.example.extension.MyLoadBalanceListener
;
import
com.nepxion.discovery.plugin.example.extension.MyRegisterListener
;
import
com.nepxion.discovery.plugin.example.extension.MyRegisterListener
;
...
@@ -49,4 +50,9 @@ public class DiscoveryApplicationA1 {
...
@@ -49,4 +50,9 @@ public class DiscoveryApplicationA1 {
public
MySubscriber
mySubscriber
()
{
public
MySubscriber
mySubscriber
()
{
return
new
MySubscriber
();
return
new
MySubscriber
();
}
}
@Bean
public
MyDiscoveryEnabledAdapter
MyDiscoveryEnabledAdapter
()
{
return
new
MyDiscoveryEnabledAdapter
();
}
}
}
\ No newline at end of file
discovery-springcloud-example/src/main/java/com/nepxion/discovery/plugin/example/feign/AFeignImpl.java
View file @
4c7291cf
...
@@ -9,6 +9,8 @@ package com.nepxion.discovery.plugin.example.feign;
...
@@ -9,6 +9,8 @@ package com.nepxion.discovery.plugin.example.feign;
* @version 1.0
* @version 1.0
*/
*/
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestBody
;
...
@@ -19,6 +21,8 @@ import com.nepxion.discovery.plugin.framework.constant.PluginConstant;
...
@@ -19,6 +21,8 @@ import com.nepxion.discovery.plugin.framework.constant.PluginConstant;
@RestController
@RestController
@ConditionalOnProperty
(
name
=
PluginConstant
.
SPRING_APPLICATION_NAME
,
havingValue
=
"discovery-springcloud-example-a"
)
@ConditionalOnProperty
(
name
=
PluginConstant
.
SPRING_APPLICATION_NAME
,
havingValue
=
"discovery-springcloud-example-a"
)
public
class
AFeignImpl
extends
AbstractFeignImpl
implements
AFeign
{
public
class
AFeignImpl
extends
AbstractFeignImpl
implements
AFeign
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
AFeignImpl
.
class
);
@Autowired
@Autowired
private
BFeign
bFeign
;
private
BFeign
bFeign
;
...
@@ -27,7 +31,7 @@ public class AFeignImpl extends AbstractFeignImpl implements AFeign {
...
@@ -27,7 +31,7 @@ public class AFeignImpl extends AbstractFeignImpl implements AFeign {
value
=
doInvoke
(
value
);
value
=
doInvoke
(
value
);
value
=
bFeign
.
invoke
(
value
);
value
=
bFeign
.
invoke
(
value
);
System
.
out
.
println
(
"调用路径:"
+
value
);
LOG
.
info
(
"调用路径:{}"
,
value
);
return
value
;
return
value
;
}
}
...
...
discovery-springcloud-example/src/main/java/com/nepxion/discovery/plugin/example/feign/BFeignImpl.java
View file @
4c7291cf
...
@@ -9,6 +9,8 @@ package com.nepxion.discovery.plugin.example.feign;
...
@@ -9,6 +9,8 @@ package com.nepxion.discovery.plugin.example.feign;
* @version 1.0
* @version 1.0
*/
*/
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestBody
;
...
@@ -19,6 +21,8 @@ import com.nepxion.discovery.plugin.framework.constant.PluginConstant;
...
@@ -19,6 +21,8 @@ import com.nepxion.discovery.plugin.framework.constant.PluginConstant;
@RestController
@RestController
@ConditionalOnProperty
(
name
=
PluginConstant
.
SPRING_APPLICATION_NAME
,
havingValue
=
"discovery-springcloud-example-b"
)
@ConditionalOnProperty
(
name
=
PluginConstant
.
SPRING_APPLICATION_NAME
,
havingValue
=
"discovery-springcloud-example-b"
)
public
class
BFeignImpl
extends
AbstractFeignImpl
implements
BFeign
{
public
class
BFeignImpl
extends
AbstractFeignImpl
implements
BFeign
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
BFeignImpl
.
class
);
@Autowired
@Autowired
private
CFeign
cFeign
;
private
CFeign
cFeign
;
...
@@ -27,7 +31,7 @@ public class BFeignImpl extends AbstractFeignImpl implements BFeign {
...
@@ -27,7 +31,7 @@ public class BFeignImpl extends AbstractFeignImpl implements BFeign {
value
=
doInvoke
(
value
);
value
=
doInvoke
(
value
);
value
=
cFeign
.
invoke
(
value
);
value
=
cFeign
.
invoke
(
value
);
System
.
out
.
println
(
"调用路径:"
+
value
);
LOG
.
info
(
"调用路径:{}"
,
value
);
return
value
;
return
value
;
}
}
...
...
discovery-springcloud-example/src/main/java/com/nepxion/discovery/plugin/example/feign/CFeignImpl.java
View file @
4c7291cf
...
@@ -9,6 +9,8 @@ package com.nepxion.discovery.plugin.example.feign;
...
@@ -9,6 +9,8 @@ package com.nepxion.discovery.plugin.example.feign;
* @version 1.0
* @version 1.0
*/
*/
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
...
@@ -18,11 +20,13 @@ import com.nepxion.discovery.plugin.framework.constant.PluginConstant;
...
@@ -18,11 +20,13 @@ import com.nepxion.discovery.plugin.framework.constant.PluginConstant;
@RestController
@RestController
@ConditionalOnProperty
(
name
=
PluginConstant
.
SPRING_APPLICATION_NAME
,
havingValue
=
"discovery-springcloud-example-c"
)
@ConditionalOnProperty
(
name
=
PluginConstant
.
SPRING_APPLICATION_NAME
,
havingValue
=
"discovery-springcloud-example-c"
)
public
class
CFeignImpl
extends
AbstractFeignImpl
implements
CFeign
{
public
class
CFeignImpl
extends
AbstractFeignImpl
implements
CFeign
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
CFeignImpl
.
class
);
@Override
@Override
public
String
invoke
(
@RequestBody
String
value
)
{
public
String
invoke
(
@RequestBody
String
value
)
{
value
=
doInvoke
(
value
);
value
=
doInvoke
(
value
);
System
.
out
.
println
(
"调用路径:"
+
value
);
LOG
.
info
(
"调用路径:{}"
,
value
);
return
value
;
return
value
;
}
}
...
...
discovery-springcloud-example/src/main/resources/bootstrap.properties
View file @
4c7291cf
...
@@ -43,6 +43,14 @@ spring.application.config.path=classpath:rule.xml
...
@@ -43,6 +43,14 @@ spring.application.config.path=classpath:rule.xml
# spring.application.group.key=group
# spring.application.group.key=group
# spring.application.group.key=application
# spring.application.group.key=application
# Plugin strategy config
# 开启和关闭用户自定义和编程灰度路由策略的控制,包括跟业务无关(例如:不允许某个服务器的IP地址或者某个版本被负载均衡到)和业务数据(例如用户根据业务参数的不同,负载均衡到不同的服务器)有关两种,该功能只支持服务,不支持网关。缺失则默认为true
spring.application.strategy.control.enabled
=
true
# 开启和关闭用户自定义和编程灰度路由策略的业务有关性的控制。一旦关闭,从业务接口无法把数据传递到上下文对象(StrategyContext);一旦开启,需要设置下面的scan.packages。缺失则默认为true
spring.application.strategy.business.context.control.enabled
=
true
# 用户自定义和编程灰度路由策略的时候,需要指定对业务Controller类的扫描路径,以便传递上下文对象
spring.application.strategy.business.scan.packages
=
com.nepxion.discovery.plugin.example.feign
# Swagger config
# Swagger config
swagger.service.base.package
=
com.nepxion.discovery.plugin.admincenter.endpoint
swagger.service.base.package
=
com.nepxion.discovery.plugin.admincenter.endpoint
swagger.service.description
=
Admin Center Restful APIs
swagger.service.description
=
Admin Center Restful APIs
...
...
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