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
4bf2cd9e
Commit
4bf2cd9e
authored
Apr 24, 2019
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
元数据增加服务名
parent
5012a387
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
45 additions
and
18 deletions
+45
-18
discovery-plugin-framework-consul/src/main/java/com/nepxion/discovery/plugin/framework/context/ConsulApplicationContextInitializer.java
+1
-0
discovery-plugin-framework-eureka/src/main/java/com/nepxion/discovery/plugin/framework/context/EurekaApplicationContextInitializer.java
+1
-0
discovery-plugin-framework-nacos/src/main/java/com/nepxion/discovery/plugin/framework/context/NacosApplicationContextInitializer.java
+1
-0
discovery-plugin-framework-zookeeper/src/main/java/com/nepxion/discovery/plugin/framework/context/ZookeeperApplicationContextInitializer.java
+1
-0
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/adapter/AbstractPluginAdapter.java
+5
-0
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/adapter/PluginAdapter.java
+2
-0
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/context/PluginContextAware.java
+4
-0
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/loadbalance/WeightRandomLoadBalance.java
+1
-1
discovery-plugin-strategy-starter-gateway/src/main/java/com/nepxion/discovery/plugin/strategy/gateway/adapter/DefaultDiscoveryEnabledAdapter.java
+3
-3
discovery-plugin-strategy-starter-service/src/main/java/com/nepxion/discovery/plugin/strategy/service/adapter/DefaultDiscoveryEnabledAdapter.java
+3
-3
discovery-plugin-strategy-starter-zuul/src/main/java/com/nepxion/discovery/plugin/strategy/zuul/adapter/DefaultDiscoveryEnabledAdapter.java
+3
-3
discovery-plugin-strategy/src/main/java/com/nepxion/discovery/plugin/strategy/adapter/AbstractDiscoveryEnabledAdapter.java
+4
-4
discovery-springcloud-example-gateway/src/main/java/com/nepxion/discovery/plugin/example/gateway/impl/MyDiscoveryEnabledStrategy.java
+5
-1
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/impl/MyDiscoveryEnabledStrategy.java
+6
-2
discovery-springcloud-example-zuul/src/main/java/com/nepxion/discovery/plugin/example/zuul/impl/MyDiscoveryEnabledStrategy.java
+5
-1
No files found.
discovery-plugin-framework-consul/src/main/java/com/nepxion/discovery/plugin/framework/context/ConsulApplicationContextInitializer.java
View file @
4bf2cd9e
...
...
@@ -36,6 +36,7 @@ public class ConsulApplicationContextInitializer extends PluginApplicationContex
consulDiscoveryProperties
.
setPreferIpAddress
(
true
);
List
<
String
>
tags
=
consulDiscoveryProperties
.
getTags
();
tags
.
add
(
DiscoveryConstant
.
SPRING_APPLICATION_NAME
+
"="
+
PluginContextAware
.
getApplicationName
(
environment
));
tags
.
add
(
DiscoveryConstant
.
SPRING_APPLICATION_DISCOVERY_PLUGIN
+
"="
+
ConsulConstant
.
DISCOVERY_PLUGIN
);
tags
.
add
(
DiscoveryConstant
.
SPRING_APPLICATION_DISCOVERY_VERSION
+
"="
+
DiscoveryConstant
.
DISCOVERY_VERSION
);
tags
.
add
(
DiscoveryConstant
.
SPRING_APPLICATION_REGISTER_CONTROL_ENABLED
+
"="
+
PluginContextAware
.
isRegisterControlEnabled
(
environment
));
...
...
discovery-plugin-framework-eureka/src/main/java/com/nepxion/discovery/plugin/framework/context/EurekaApplicationContextInitializer.java
View file @
4bf2cd9e
...
...
@@ -36,6 +36,7 @@ public class EurekaApplicationContextInitializer extends PluginApplicationContex
eurekaInstanceConfig
.
setPreferIpAddress
(
true
);
Map
<
String
,
String
>
metadataMap
=
eurekaInstanceConfig
.
getMetadataMap
();
metadataMap
.
put
(
DiscoveryConstant
.
SPRING_APPLICATION_NAME
,
PluginContextAware
.
getApplicationName
(
environment
));
metadataMap
.
put
(
DiscoveryConstant
.
SPRING_APPLICATION_DISCOVERY_PLUGIN
,
EurekaConstant
.
DISCOVERY_PLUGIN
);
metadataMap
.
put
(
DiscoveryConstant
.
SPRING_APPLICATION_DISCOVERY_VERSION
,
DiscoveryConstant
.
DISCOVERY_VERSION
);
metadataMap
.
put
(
DiscoveryConstant
.
SPRING_APPLICATION_REGISTER_CONTROL_ENABLED
,
PluginContextAware
.
isRegisterControlEnabled
(
environment
).
toString
());
...
...
discovery-plugin-framework-nacos/src/main/java/com/nepxion/discovery/plugin/framework/context/NacosApplicationContextInitializer.java
View file @
4bf2cd9e
...
...
@@ -35,6 +35,7 @@ public class NacosApplicationContextInitializer extends PluginApplicationContext
NacosDiscoveryProperties
nacosDiscoveryProperties
=
(
NacosDiscoveryProperties
)
bean
;
Map
<
String
,
String
>
metadata
=
nacosDiscoveryProperties
.
getMetadata
();
metadata
.
put
(
DiscoveryConstant
.
SPRING_APPLICATION_NAME
,
PluginContextAware
.
getApplicationName
(
environment
));
metadata
.
put
(
DiscoveryConstant
.
SPRING_APPLICATION_DISCOVERY_PLUGIN
,
NacosConstant
.
DISCOVERY_PLUGIN
);
metadata
.
put
(
DiscoveryConstant
.
SPRING_APPLICATION_DISCOVERY_VERSION
,
DiscoveryConstant
.
DISCOVERY_VERSION
);
metadata
.
put
(
DiscoveryConstant
.
SPRING_APPLICATION_REGISTER_CONTROL_ENABLED
,
PluginContextAware
.
isRegisterControlEnabled
(
environment
).
toString
());
...
...
discovery-plugin-framework-zookeeper/src/main/java/com/nepxion/discovery/plugin/framework/context/ZookeeperApplicationContextInitializer.java
View file @
4bf2cd9e
...
...
@@ -36,6 +36,7 @@ public class ZookeeperApplicationContextInitializer extends PluginApplicationCon
zookeeperDiscoveryProperties
.
setPreferIpAddress
(
true
);
Map
<
String
,
String
>
metadata
=
zookeeperDiscoveryProperties
.
getMetadata
();
metadata
.
put
(
DiscoveryConstant
.
SPRING_APPLICATION_NAME
,
PluginContextAware
.
getApplicationName
(
environment
));
metadata
.
put
(
DiscoveryConstant
.
SPRING_APPLICATION_DISCOVERY_PLUGIN
,
ZookeeperConstant
.
DISCOVERY_PLUGIN
);
metadata
.
put
(
DiscoveryConstant
.
SPRING_APPLICATION_DISCOVERY_VERSION
,
DiscoveryConstant
.
DISCOVERY_VERSION
);
metadata
.
put
(
DiscoveryConstant
.
SPRING_APPLICATION_REGISTER_CONTROL_ENABLED
,
PluginContextAware
.
isRegisterControlEnabled
(
environment
).
toString
());
...
...
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/adapter/AbstractPluginAdapter.java
View file @
4bf2cd9e
...
...
@@ -148,6 +148,11 @@ public abstract class AbstractPluginAdapter implements PluginAdapter {
}
@Override
public
String
getServerServiceId
(
Server
server
)
{
return
getServerMetadata
(
server
).
get
(
DiscoveryConstant
.
SPRING_APPLICATION_NAME
).
toLowerCase
();
}
@Override
public
String
getServerVersion
(
Server
server
)
{
return
getServerMetadata
(
server
).
get
(
DiscoveryConstant
.
VERSION
);
}
...
...
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/adapter/PluginAdapter.java
View file @
4bf2cd9e
...
...
@@ -53,6 +53,8 @@ public interface PluginAdapter {
Map
<
String
,
String
>
getServerMetadata
(
Server
server
);
String
getServerServiceId
(
Server
server
);
String
getServerVersion
(
Server
server
);
String
getServerRegion
(
Server
server
);
...
...
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/context/PluginContextAware.java
View file @
4bf2cd9e
...
...
@@ -133,6 +133,10 @@ public class PluginContextAware implements ApplicationContextAware {
return
environment
.
getProperty
(
DiscoveryConstant
.
SPRING_APPLICATION_CONFIG_PATH
,
String
.
class
,
StringUtils
.
equals
(
getConfigFormat
(
environment
),
DiscoveryConstant
.
XML_FORMAT
)
?
DiscoveryConstant
.
PREFIX_CLASSPATH
+
DiscoveryConstant
.
RULE
+
"."
+
DiscoveryConstant
.
XML_FORMAT
:
DiscoveryConstant
.
PREFIX_CLASSPATH
+
DiscoveryConstant
.
RULE
+
"."
+
DiscoveryConstant
.
JSON_FORMAT
);
}
public
static
String
getApplicationName
(
Environment
environment
)
{
return
environment
.
getProperty
(
DiscoveryConstant
.
SPRING_APPLICATION_NAME
);
}
public
static
String
getGroupKey
(
Environment
environment
)
{
return
environment
.
getProperty
(
DiscoveryConstant
.
SPRING_APPLICATION_GROUP_KEY
,
String
.
class
,
DiscoveryConstant
.
GROUP
);
}
...
...
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/loadbalance/WeightRandomLoadBalance.java
View file @
4bf2cd9e
...
...
@@ -96,7 +96,7 @@ public class WeightRandomLoadBalance {
Map
<
String
,
List
<
WeightEntity
>>
weightEntityMap
=
weightFilterEntity
.
getWeightEntityMap
();
RegionWeightEntity
regionWeightEntity
=
weightFilterEntity
.
getRegionWeightEntity
();
String
providerServiceId
=
server
.
getMetaInfo
().
getAppName
(
);
String
providerServiceId
=
pluginAdapter
.
getServerServiceId
(
server
);
String
providerVersion
=
pluginAdapter
.
getServerVersion
(
server
);
String
providerRegion
=
pluginAdapter
.
getServerRegion
(
server
);
...
...
discovery-plugin-strategy-starter-gateway/src/main/java/com/nepxion/discovery/plugin/strategy/gateway/adapter/DefaultDiscoveryEnabledAdapter.java
View file @
4bf2cd9e
...
...
@@ -29,7 +29,7 @@ public class DefaultDiscoveryEnabledAdapter extends AbstractDiscoveryEnabledAdap
protected
String
getVersionValue
(
Server
server
)
{
ServerWebExchange
exchange
=
gatewayStrategyContextHolder
.
getExchange
();
if
(
exchange
==
null
)
{
String
serviceId
=
server
.
getMetaInfo
().
getAppName
().
toLowerCase
(
);
String
serviceId
=
pluginAdapter
.
getServerServiceId
(
server
);
LOG
.
warn
(
"The ServerWebExchange object is null, ignore to do version filter for service={}..."
,
serviceId
);
...
...
@@ -43,7 +43,7 @@ public class DefaultDiscoveryEnabledAdapter extends AbstractDiscoveryEnabledAdap
protected
String
getRegionValue
(
Server
server
)
{
ServerWebExchange
exchange
=
gatewayStrategyContextHolder
.
getExchange
();
if
(
exchange
==
null
)
{
String
serviceId
=
server
.
getMetaInfo
().
getAppName
().
toLowerCase
(
);
String
serviceId
=
pluginAdapter
.
getServerServiceId
(
server
);
LOG
.
warn
(
"The ServerWebExchange object is null, ignore to do region filter for service={}..."
,
serviceId
);
...
...
@@ -57,7 +57,7 @@ public class DefaultDiscoveryEnabledAdapter extends AbstractDiscoveryEnabledAdap
protected
String
getAddressValue
(
Server
server
)
{
ServerWebExchange
exchange
=
gatewayStrategyContextHolder
.
getExchange
();
if
(
exchange
==
null
)
{
String
serviceId
=
server
.
getMetaInfo
().
getAppName
().
toLowerCase
(
);
String
serviceId
=
pluginAdapter
.
getServerServiceId
(
server
);
LOG
.
warn
(
"The ServerWebExchange object is null, ignore to do region filter for service={}..."
,
serviceId
);
...
...
discovery-plugin-strategy-starter-service/src/main/java/com/nepxion/discovery/plugin/strategy/service/adapter/DefaultDiscoveryEnabledAdapter.java
View file @
4bf2cd9e
...
...
@@ -29,7 +29,7 @@ public class DefaultDiscoveryEnabledAdapter extends AbstractDiscoveryEnabledAdap
protected
String
getVersionValue
(
Server
server
)
{
ServletRequestAttributes
attributes
=
serviceStrategyContextHolder
.
getRestAttributes
();
if
(
attributes
==
null
)
{
String
serviceId
=
server
.
getMetaInfo
().
getAppName
().
toLowerCase
(
);
String
serviceId
=
pluginAdapter
.
getServerServiceId
(
server
);
LOG
.
warn
(
"The ServletRequestAttributes object is null, ignore to do version filter for service={}..."
,
serviceId
);
...
...
@@ -43,7 +43,7 @@ public class DefaultDiscoveryEnabledAdapter extends AbstractDiscoveryEnabledAdap
protected
String
getRegionValue
(
Server
server
)
{
ServletRequestAttributes
attributes
=
serviceStrategyContextHolder
.
getRestAttributes
();
if
(
attributes
==
null
)
{
String
serviceId
=
server
.
getMetaInfo
().
getAppName
().
toLowerCase
(
);
String
serviceId
=
pluginAdapter
.
getServerServiceId
(
server
);
LOG
.
warn
(
"The ServletRequestAttributes object is null, ignore to do region filter for service={}..."
,
serviceId
);
...
...
@@ -57,7 +57,7 @@ public class DefaultDiscoveryEnabledAdapter extends AbstractDiscoveryEnabledAdap
protected
String
getAddressValue
(
Server
server
)
{
ServletRequestAttributes
attributes
=
serviceStrategyContextHolder
.
getRestAttributes
();
if
(
attributes
==
null
)
{
String
serviceId
=
server
.
getMetaInfo
().
getAppName
().
toLowerCase
(
);
String
serviceId
=
pluginAdapter
.
getServerServiceId
(
server
);
LOG
.
warn
(
"The ServletRequestAttributes object is null, ignore to do region filter for service={}..."
,
serviceId
);
...
...
discovery-plugin-strategy-starter-zuul/src/main/java/com/nepxion/discovery/plugin/strategy/zuul/adapter/DefaultDiscoveryEnabledAdapter.java
View file @
4bf2cd9e
...
...
@@ -30,7 +30,7 @@ public class DefaultDiscoveryEnabledAdapter extends AbstractDiscoveryEnabledAdap
protected
String
getVersionValue
(
Server
server
)
{
HttpServletRequest
request
=
zuulStrategyContextHolder
.
getRequest
();
if
(
request
==
null
)
{
String
serviceId
=
server
.
getMetaInfo
().
getAppName
().
toLowerCase
(
);
String
serviceId
=
pluginAdapter
.
getServerServiceId
(
server
);
LOG
.
warn
(
"The HttpServletRequest object is null, ignore to do version filter for service={}..."
,
serviceId
);
...
...
@@ -44,7 +44,7 @@ public class DefaultDiscoveryEnabledAdapter extends AbstractDiscoveryEnabledAdap
protected
String
getRegionValue
(
Server
server
)
{
HttpServletRequest
request
=
zuulStrategyContextHolder
.
getRequest
();
if
(
request
==
null
)
{
String
serviceId
=
server
.
getMetaInfo
().
getAppName
().
toLowerCase
(
);
String
serviceId
=
pluginAdapter
.
getServerServiceId
(
server
);
LOG
.
warn
(
"The HttpServletRequest object is null, ignore to do region filter for service={}..."
,
serviceId
);
...
...
@@ -58,7 +58,7 @@ public class DefaultDiscoveryEnabledAdapter extends AbstractDiscoveryEnabledAdap
protected
String
getAddressValue
(
Server
server
)
{
HttpServletRequest
request
=
zuulStrategyContextHolder
.
getRequest
();
if
(
request
==
null
)
{
String
serviceId
=
server
.
getMetaInfo
().
getAppName
().
toLowerCase
(
);
String
serviceId
=
pluginAdapter
.
getServerServiceId
(
server
);
LOG
.
warn
(
"The HttpServletRequest object is null, ignore to do region filter for service={}..."
,
serviceId
);
...
...
discovery-plugin-strategy/src/main/java/com/nepxion/discovery/plugin/strategy/adapter/AbstractDiscoveryEnabledAdapter.java
View file @
4bf2cd9e
...
...
@@ -28,7 +28,7 @@ public abstract class AbstractDiscoveryEnabledAdapter implements DiscoveryEnable
private
DiscoveryEnabledStrategy
discoveryEnabledStrategy
;
@Autowired
pr
ivate
PluginAdapter
pluginAdapter
;
pr
otected
PluginAdapter
pluginAdapter
;
@Override
public
boolean
apply
(
Server
server
,
Map
<
String
,
String
>
metadata
)
{
...
...
@@ -75,7 +75,7 @@ public abstract class AbstractDiscoveryEnabledAdapter implements DiscoveryEnable
String
versions
=
null
;
try
{
Map
<
String
,
String
>
versionMap
=
JsonUtil
.
fromJson
(
versionValue
,
Map
.
class
);
String
serviceId
=
server
.
getMetaInfo
().
getAppName
().
toLowerCase
(
);
String
serviceId
=
pluginAdapter
.
getServerServiceId
(
server
);
versions
=
versionMap
.
get
(
serviceId
);
}
catch
(
Exception
e
)
{
versions
=
versionValue
;
...
...
@@ -118,7 +118,7 @@ public abstract class AbstractDiscoveryEnabledAdapter implements DiscoveryEnable
String
regions
=
null
;
try
{
Map
<
String
,
String
>
regionMap
=
JsonUtil
.
fromJson
(
regionValue
,
Map
.
class
);
String
serviceId
=
server
.
getMetaInfo
().
getAppName
().
toLowerCase
(
);
String
serviceId
=
pluginAdapter
.
getServerServiceId
(
server
);
regions
=
regionMap
.
get
(
serviceId
);
}
catch
(
Exception
e
)
{
regions
=
regionValue
;
...
...
@@ -154,7 +154,7 @@ public abstract class AbstractDiscoveryEnabledAdapter implements DiscoveryEnable
}
Map
<
String
,
String
>
addressMap
=
JsonUtil
.
fromJson
(
addressValue
,
Map
.
class
);
String
serviceId
=
server
.
getMetaInfo
().
getAppName
().
toLowerCase
(
);
String
serviceId
=
pluginAdapter
.
getServerServiceId
(
server
);
String
addresses
=
addressMap
.
get
(
serviceId
);
if
(
StringUtils
.
isEmpty
(
addresses
))
{
return
true
;
...
...
discovery-springcloud-example-gateway/src/main/java/com/nepxion/discovery/plugin/example/gateway/impl/MyDiscoveryEnabledStrategy.java
View file @
4bf2cd9e
...
...
@@ -17,6 +17,7 @@ import org.slf4j.LoggerFactory;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.server.ServerWebExchange
;
import
com.nepxion.discovery.plugin.framework.adapter.PluginAdapter
;
import
com.nepxion.discovery.plugin.strategy.adapter.DiscoveryEnabledStrategy
;
import
com.nepxion.discovery.plugin.strategy.gateway.context.GatewayStrategyContextHolder
;
import
com.netflix.loadbalancer.Server
;
...
...
@@ -28,6 +29,9 @@ public class MyDiscoveryEnabledStrategy implements DiscoveryEnabledStrategy {
@Autowired
private
GatewayStrategyContextHolder
gatewayStrategyContextHolder
;
@Autowired
private
PluginAdapter
pluginAdapter
;
@Override
public
boolean
apply
(
Server
server
,
Map
<
String
,
String
>
metadata
)
{
// 对Rest调用传来的Header参数(例如Token)做策略
...
...
@@ -44,7 +48,7 @@ public class MyDiscoveryEnabledStrategy implements DiscoveryEnabledStrategy {
String
token
=
exchange
.
getRequest
().
getHeaders
().
getFirst
(
"token"
);
// String value = exchange.getRequest().getQueryParams().getFirst("value");
String
serviceId
=
server
.
getMetaInfo
().
getAppName
().
toLowerCase
(
);
String
serviceId
=
pluginAdapter
.
getServerServiceId
(
server
);
LOG
.
info
(
"Gateway端负载均衡用户定制触发:serviceId={}, host={}, metadata={}"
,
serviceId
,
server
.
toString
(),
metadata
);
...
...
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/impl/MyDiscoveryEnabledStrategy.java
View file @
4bf2cd9e
...
...
@@ -18,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
com.nepxion.discovery.common.constant.DiscoveryConstant
;
import
com.nepxion.discovery.plugin.framework.adapter.PluginAdapter
;
import
com.nepxion.discovery.plugin.strategy.adapter.DiscoveryEnabledStrategy
;
import
com.nepxion.discovery.plugin.strategy.service.constant.ServiceStrategyConstant
;
import
com.nepxion.discovery.plugin.strategy.service.context.ServiceStrategyContextHolder
;
...
...
@@ -30,6 +31,9 @@ public class MyDiscoveryEnabledStrategy implements DiscoveryEnabledStrategy {
@Autowired
private
ServiceStrategyContextHolder
serviceStrategyContextHolder
;
@Autowired
private
PluginAdapter
pluginAdapter
;
@Override
public
boolean
apply
(
Server
server
,
Map
<
String
,
String
>
metadata
)
{
// 对Rest调用传来的Header参数(例如Token)做策略
...
...
@@ -52,7 +56,7 @@ public class MyDiscoveryEnabledStrategy implements DiscoveryEnabledStrategy {
String
token
=
attributes
.
getRequest
().
getHeader
(
"token"
);
// String value = attributes.getRequest().getParameter("value");
String
serviceId
=
server
.
getMetaInfo
().
getAppName
().
toLowerCase
(
);
String
serviceId
=
pluginAdapter
.
getServerServiceId
(
server
);
LOG
.
info
(
"Serivice端负载均衡用户定制触发:serviceId={}, host={}, metadata={}, attributes={}"
,
serviceId
,
server
.
toString
(),
metadata
,
attributes
);
...
...
@@ -72,7 +76,7 @@ public class MyDiscoveryEnabledStrategy implements DiscoveryEnabledStrategy {
private
boolean
applyFromMethod
(
Server
server
,
Map
<
String
,
String
>
metadata
)
{
Map
<
String
,
Object
>
attributes
=
serviceStrategyContextHolder
.
getRpcAttributes
();
String
serviceId
=
server
.
getMetaInfo
().
getAppName
().
toLowerCase
(
);
String
serviceId
=
pluginAdapter
.
getServerServiceId
(
server
);
String
version
=
metadata
.
get
(
DiscoveryConstant
.
VERSION
);
LOG
.
info
(
"Serivice端负载均衡用户定制触发:serviceId={}, host={}, metadata={}, attributes={}"
,
serviceId
,
server
.
toString
(),
metadata
,
attributes
);
...
...
discovery-springcloud-example-zuul/src/main/java/com/nepxion/discovery/plugin/example/zuul/impl/MyDiscoveryEnabledStrategy.java
View file @
4bf2cd9e
...
...
@@ -18,6 +18,7 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
com.nepxion.discovery.plugin.framework.adapter.PluginAdapter
;
import
com.nepxion.discovery.plugin.strategy.adapter.DiscoveryEnabledStrategy
;
import
com.nepxion.discovery.plugin.strategy.zuul.context.ZuulStrategyContextHolder
;
import
com.netflix.loadbalancer.Server
;
...
...
@@ -29,6 +30,9 @@ public class MyDiscoveryEnabledStrategy implements DiscoveryEnabledStrategy {
@Autowired
private
ZuulStrategyContextHolder
zuulStrategyContextHolder
;
@Autowired
private
PluginAdapter
pluginAdapter
;
@Override
public
boolean
apply
(
Server
server
,
Map
<
String
,
String
>
metadata
)
{
// 对Rest调用传来的Header参数(例如Token)做策略
...
...
@@ -45,7 +49,7 @@ public class MyDiscoveryEnabledStrategy implements DiscoveryEnabledStrategy {
String
token
=
request
.
getHeader
(
"token"
);
// String value = request.getParameter("value");
String
serviceId
=
server
.
getMetaInfo
().
getAppName
().
toLowerCase
(
);
String
serviceId
=
pluginAdapter
.
getServerServiceId
(
server
);
LOG
.
info
(
"Zuul端负载均衡用户定制触发:serviceId={}, host={}, metadata={}"
,
serviceId
,
server
.
toString
(),
metadata
);
...
...
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