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
22920e1a
Commit
22920e1a
authored
May 31, 2019
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改示例
parent
702a918f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
6 deletions
+6
-6
discovery-springcloud-example-gateway/src/main/java/com/nepxion/discovery/plugin/example/gateway/impl/MyDiscoveryEnabledStrategy.java
+2
-2
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/impl/MyDiscoveryEnabledStrategy.java
+2
-2
discovery-springcloud-example-zuul/src/main/java/com/nepxion/discovery/plugin/example/zuul/impl/MyDiscoveryEnabledStrategy.java
+2
-2
No files found.
discovery-springcloud-example-gateway/src/main/java/com/nepxion/discovery/plugin/example/gateway/impl/MyDiscoveryEnabledStrategy.java
View file @
22920e1a
...
@@ -34,11 +34,11 @@ public class MyDiscoveryEnabledStrategy implements DiscoveryEnabledStrategy {
...
@@ -34,11 +34,11 @@ public class MyDiscoveryEnabledStrategy implements DiscoveryEnabledStrategy {
@Override
@Override
public
boolean
apply
(
Server
server
,
Map
<
String
,
String
>
metadata
)
{
public
boolean
apply
(
Server
server
,
Map
<
String
,
String
>
metadata
)
{
// 对Rest调用传来的Header参数(例如
Token
)做策略
// 对Rest调用传来的Header参数(例如
:mobile
)做策略
return
applyFromHeader
(
server
,
metadata
);
return
applyFromHeader
(
server
,
metadata
);
}
}
// 根据Rest调用传来的Header参数(例如
Token
),选取执行调用请求的服务实例
// 根据Rest调用传来的Header参数(例如
:mobile
),选取执行调用请求的服务实例
private
boolean
applyFromHeader
(
Server
server
,
Map
<
String
,
String
>
metadata
)
{
private
boolean
applyFromHeader
(
Server
server
,
Map
<
String
,
String
>
metadata
)
{
String
mobile
=
gatewayStrategyContextHolder
.
getHeader
(
"mobile"
);
String
mobile
=
gatewayStrategyContextHolder
.
getHeader
(
"mobile"
);
String
version
=
metadata
.
get
(
DiscoveryConstant
.
VERSION
);
String
version
=
metadata
.
get
(
DiscoveryConstant
.
VERSION
);
...
...
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/impl/MyDiscoveryEnabledStrategy.java
View file @
22920e1a
...
@@ -35,7 +35,7 @@ public class MyDiscoveryEnabledStrategy implements DiscoveryEnabledStrategy {
...
@@ -35,7 +35,7 @@ public class MyDiscoveryEnabledStrategy implements DiscoveryEnabledStrategy {
@Override
@Override
public
boolean
apply
(
Server
server
,
Map
<
String
,
String
>
metadata
)
{
public
boolean
apply
(
Server
server
,
Map
<
String
,
String
>
metadata
)
{
// 对Rest调用传来的Header参数(例如
T
oken)做策略
// 对Rest调用传来的Header参数(例如
:t
oken)做策略
boolean
enabled
=
applyFromHeader
(
server
,
metadata
);
boolean
enabled
=
applyFromHeader
(
server
,
metadata
);
if
(!
enabled
)
{
if
(!
enabled
)
{
return
false
;
return
false
;
...
@@ -45,7 +45,7 @@ public class MyDiscoveryEnabledStrategy implements DiscoveryEnabledStrategy {
...
@@ -45,7 +45,7 @@ public class MyDiscoveryEnabledStrategy implements DiscoveryEnabledStrategy {
return
applyFromMethod
(
server
,
metadata
);
return
applyFromMethod
(
server
,
metadata
);
}
}
// 根据Rest调用传来的Header参数(例如
T
oken),选取执行调用请求的服务实例
// 根据Rest调用传来的Header参数(例如
:t
oken),选取执行调用请求的服务实例
private
boolean
applyFromHeader
(
Server
server
,
Map
<
String
,
String
>
metadata
)
{
private
boolean
applyFromHeader
(
Server
server
,
Map
<
String
,
String
>
metadata
)
{
String
token
=
serviceStrategyContextHolder
.
getHeader
(
"token"
);
String
token
=
serviceStrategyContextHolder
.
getHeader
(
"token"
);
String
serviceId
=
pluginAdapter
.
getServerServiceId
(
server
);
String
serviceId
=
pluginAdapter
.
getServerServiceId
(
server
);
...
...
discovery-springcloud-example-zuul/src/main/java/com/nepxion/discovery/plugin/example/zuul/impl/MyDiscoveryEnabledStrategy.java
View file @
22920e1a
...
@@ -34,11 +34,11 @@ public class MyDiscoveryEnabledStrategy implements DiscoveryEnabledStrategy {
...
@@ -34,11 +34,11 @@ public class MyDiscoveryEnabledStrategy implements DiscoveryEnabledStrategy {
@Override
@Override
public
boolean
apply
(
Server
server
,
Map
<
String
,
String
>
metadata
)
{
public
boolean
apply
(
Server
server
,
Map
<
String
,
String
>
metadata
)
{
// 对Rest调用传来的Header参数(例如
Token
)做策略
// 对Rest调用传来的Header参数(例如
:mobile
)做策略
return
applyFromHeader
(
server
,
metadata
);
return
applyFromHeader
(
server
,
metadata
);
}
}
// 根据Rest调用传来的Header参数(例如
Token
),选取执行调用请求的服务实例
// 根据Rest调用传来的Header参数(例如
:mobile
),选取执行调用请求的服务实例
private
boolean
applyFromHeader
(
Server
server
,
Map
<
String
,
String
>
metadata
)
{
private
boolean
applyFromHeader
(
Server
server
,
Map
<
String
,
String
>
metadata
)
{
String
mobile
=
zuulStrategyContextHolder
.
getHeader
(
"mobile"
);
String
mobile
=
zuulStrategyContextHolder
.
getHeader
(
"mobile"
);
String
version
=
metadata
.
get
(
DiscoveryConstant
.
VERSION
);
String
version
=
metadata
.
get
(
DiscoveryConstant
.
VERSION
);
...
...
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