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
4c366510
Commit
4c366510
authored
May 20, 2019
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加路由策略过滤器的执行顺序配置项
parent
cb4bf6b0
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
5 deletions
+30
-5
discovery-plugin-strategy-starter-gateway/src/main/java/com/nepxion/discovery/plugin/strategy/gateway/constant/GatewayStrategyConstant.java
+15
-0
discovery-plugin-strategy-starter-gateway/src/main/java/com/nepxion/discovery/plugin/strategy/gateway/filter/GatewayStrategyFilter.java
+8
-1
discovery-springcloud-example-gateway/src/main/java/com/nepxion/discovery/plugin/example/gateway/impl/MyGatewayFilter.java
+3
-2
discovery-springcloud-example-gateway/src/main/resources/bootstrap.properties
+4
-2
No files found.
discovery-plugin-strategy-starter-gateway/src/main/java/com/nepxion/discovery/plugin/strategy/gateway/constant/GatewayStrategyConstant.java
0 → 100644
View file @
4c366510
package
com
.
nepxion
.
discovery
.
plugin
.
strategy
.
gateway
.
constant
;
/**
* <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
*/
public
class
GatewayStrategyConstant
{
public
static
final
String
SPRING_APPLICATION_STRATEGY_GATEWAY_FILTER_ORDER
=
"spring.application.strategy.gateway.filter.order"
;
}
\ No newline at end of file
discovery-plugin-strategy-starter-gateway/src/main/java/com/nepxion/discovery/plugin/strategy/gateway/filter/GatewayStrategyFilter.java
View file @
4c366510
...
...
@@ -13,16 +13,22 @@ import reactor.core.publisher.Mono;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cloud.gateway.filter.GatewayFilterChain
;
import
org.springframework.cloud.gateway.filter.GlobalFilter
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
org.springframework.web.server.ServerWebExchange
;
import
com.nepxion.discovery.plugin.strategy.gateway.constant.GatewayStrategyConstant
;
import
com.nepxion.discovery.plugin.strategy.gateway.context.GatewayStrategyContext
;
public
class
GatewayStrategyFilter
implements
GlobalFilter
,
Ordered
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
GatewayStrategyFilter
.
class
);
@Autowired
private
ConfigurableEnvironment
environment
;
@Override
public
Mono
<
Void
>
filter
(
ServerWebExchange
exchange
,
GatewayFilterChain
chain
)
{
LOG
.
debug
(
"Gateway strategy context is set with {}"
,
exchange
);
...
...
@@ -34,6 +40,6 @@ public class GatewayStrategyFilter implements GlobalFilter, Ordered {
@Override
public
int
getOrder
()
{
return
-
400
;
return
environment
.
getProperty
(
GatewayStrategyConstant
.
SPRING_APPLICATION_STRATEGY_GATEWAY_FILTER_ORDER
,
Integer
.
class
,
9999
)
;
}
}
\ No newline at end of file
discovery-springcloud-example-gateway/src/main/java/com/nepxion/discovery/plugin/example/gateway/impl/MyGatewayFilter.java
View file @
4c366510
...
...
@@ -30,7 +30,7 @@ public class MyGatewayFilter implements GlobalFilter, Ordered {
@Override
public
int
getOrder
()
{
// Order必须小于
-400
return
-
500
;
// Order必须小于
9999
return
9998
;
}
}
\ No newline at end of file
discovery-springcloud-example-gateway/src/main/resources/bootstrap.properties
View file @
4c366510
...
...
@@ -72,4 +72,6 @@ spring.boot.admin.client.url=http://localhost:5555
# 开启和关闭策略扩展功能的控制。一旦关闭,用户自定义和编程灰度路由策略功能将失效。缺失则默认为true
# spring.application.strategy.control.enabled=true
# 开启和关闭Ribbon默认的ZoneAvoidanceRule负载均衡策略。一旦关闭,则使用RoundRobin简单轮询负载均衡策略。缺失则默认为true
#
spring.application.strategy.zone.avoidance.rule.enabled
=
true
\ No newline at end of file
# spring.application.strategy.zone.avoidance.rule.enabled=true
# 路由策略过滤器的执行顺序(Order)。缺失则默认为9999
#
spring.application.strategy.gateway.filter.order
=
9999
\ 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