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
d9f0952b
Commit
d9f0952b
authored
Aug 02, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
支持设置全局context-path
parent
7ace1323
Show whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
121 additions
and
49 deletions
+121
-49
discovery-common/src/main/java/com/nepxion/discovery/common/constant/DiscoveryConstant.java
+1
-0
discovery-common/src/main/java/com/nepxion/discovery/common/entity/RouterEntity.java
+9
-14
discovery-common/src/main/java/com/nepxion/discovery/common/util/UrlUtil.java
+30
-0
discovery-console-desktop/src/main/java/com/nepxion/discovery/console/desktop/controller/ServiceController.java
+17
-16
discovery-console-desktop/src/main/java/com/nepxion/discovery/console/desktop/entity/Instance.java
+6
-0
discovery-console/src/main/java/com/nepxion/discovery/console/rest/AbstractRestInvoker.java
+6
-3
discovery-console/src/main/java/com/nepxion/discovery/console/rest/ConfigClearRestInvoker.java
+2
-2
discovery-console/src/main/java/com/nepxion/discovery/console/rest/ConfigUpdateRestInvoker.java
+2
-2
discovery-console/src/main/java/com/nepxion/discovery/console/rest/VersionClearRestInvoker.java
+2
-2
discovery-console/src/main/java/com/nepxion/discovery/console/rest/VersionUpdateRestInvoker.java
+2
-2
discovery-plugin-admin-center/src/main/java/com/nepxion/discovery/plugin/admincenter/endpoint/RouterEndpoint.java
+16
-8
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-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
+9
-0
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/feign/AFeign.java
+2
-0
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/feign/BFeign.java
+2
-0
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/feign/CFeign.java
+2
-0
discovery-springcloud-example-service/src/main/resources/bootstrap.properties
+3
-0
No files found.
discovery-common/src/main/java/com/nepxion/discovery/common/constant/DiscoveryConstant.java
View file @
d9f0952b
...
...
@@ -17,6 +17,7 @@ public class DiscoveryConstant {
public
static
final
String
SPRING_APPLICATION_CONFIG_FORMAT
=
"spring.application.config.format"
;
public
static
final
String
SPRING_APPLICATION_CONFIG_PATH
=
"spring.application.config.path"
;
public
static
final
String
SPRING_APPLICATION_GROUP_KEY
=
"spring.application.group.key"
;
public
static
final
String
SPRING_APPLICATION_CONTEXT_PATH
=
"spring.application.context-path"
;
public
static
final
String
SPRING_APPLICATION_NAME
=
"spring.application.name"
;
public
static
final
String
GROUP
=
"group"
;
...
...
discovery-common/src/main/java/com/nepxion/discovery/common/entity/RouterEntity.java
View file @
d9f0952b
...
...
@@ -18,8 +18,6 @@ import org.apache.commons.lang3.builder.HashCodeBuilder;
import
org.apache.commons.lang3.builder.ToStringBuilder
;
import
org.apache.commons.lang3.builder.ToStringStyle
;
import
com.nepxion.discovery.common.constant.DiscoveryConstant
;
public
class
RouterEntity
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
4480475963615166799L
;
...
...
@@ -27,6 +25,7 @@ public class RouterEntity implements Serializable {
private
String
version
;
private
String
host
;
private
int
port
;
private
String
contextPath
;
private
List
<
RouterEntity
>
nexts
=
new
ArrayList
<
RouterEntity
>();
...
...
@@ -62,6 +61,14 @@ public class RouterEntity implements Serializable {
this
.
port
=
port
;
}
public
String
getContextPath
()
{
return
contextPath
;
}
public
void
setContextPath
(
String
contextPath
)
{
this
.
contextPath
=
contextPath
;
}
public
List
<
RouterEntity
>
getNexts
()
{
return
nexts
;
}
...
...
@@ -70,18 +77,6 @@ public class RouterEntity implements Serializable {
this
.
nexts
=
nexts
;
}
public
String
toInfo
()
{
StringBuilder
stringBuilder
=
new
StringBuilder
();
stringBuilder
.
append
(
"["
)
.
append
(
DiscoveryConstant
.
SERVICE_ID
).
append
(
"="
).
append
(
serviceId
).
append
(
", "
)
.
append
(
DiscoveryConstant
.
VERSION
).
append
(
"="
).
append
(
version
).
append
(
", "
)
.
append
(
DiscoveryConstant
.
HOST
).
append
(
"="
).
append
(
host
).
append
(
", "
)
.
append
(
DiscoveryConstant
.
PORT
).
append
(
"="
).
append
(
port
)
.
append
(
"]"
);
return
stringBuilder
.
toString
();
}
@Override
public
int
hashCode
()
{
return
HashCodeBuilder
.
reflectionHashCode
(
this
);
...
...
discovery-common/src/main/java/com/nepxion/discovery/common/util/UrlUtil.java
0 → 100644
View file @
d9f0952b
package
com
.
nepxion
.
discovery
.
common
.
util
;
/**
* <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
*/
import
org.apache.commons.lang3.StringUtils
;
public
class
UrlUtil
{
public
static
String
formatContextPath
(
String
contextPath
)
{
if
(
StringUtils
.
isEmpty
(
contextPath
))
{
contextPath
=
"/"
;
}
else
{
if
(!
contextPath
.
startsWith
(
"/"
))
{
contextPath
=
"/"
+
contextPath
;
}
if
(!
contextPath
.
endsWith
(
"/"
))
{
contextPath
=
contextPath
+
"/"
;
}
}
return
contextPath
;
}
}
\ No newline at end of file
discovery-console-desktop/src/main/java/com/nepxion/discovery/console/desktop/controller/ServiceController.java
View file @
d9f0952b
...
...
@@ -21,6 +21,7 @@ import org.springframework.web.client.RestTemplate;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.nepxion.discovery.common.entity.ResultEntity
;
import
com.nepxion.discovery.common.entity.RouterEntity
;
import
com.nepxion.discovery.common.util.UrlUtil
;
import
com.nepxion.discovery.console.desktop.context.PropertiesContext
;
import
com.nepxion.discovery.console.desktop.entity.Instance
;
import
com.nepxion.discovery.console.desktop.serializer.JacksonSerializer
;
...
...
@@ -34,7 +35,7 @@ public class ServiceController {
}
public
static
Map
<
String
,
List
<
Instance
>>
getInstanceMap
()
{
String
url
=
getUrl
()
+
"
/
console/instance-map"
;
String
url
=
getUrl
()
+
"console/instance-map"
;
String
result
=
restTemplate
.
getForEntity
(
url
,
String
.
class
).
getBody
();
...
...
@@ -43,7 +44,7 @@ public class ServiceController {
}
public
static
List
<
String
>
getVersions
(
Instance
instance
)
{
String
url
=
getUrl
(
instance
)
+
"
/
version/view"
;
String
url
=
getUrl
(
instance
)
+
"version/view"
;
String
result
=
restTemplate
.
getForEntity
(
url
,
String
.
class
).
getBody
();
...
...
@@ -52,7 +53,7 @@ public class ServiceController {
}
public
static
List
<
String
>
getRules
(
Instance
instance
)
{
String
url
=
getUrl
(
instance
)
+
"
/
config/view"
;
String
url
=
getUrl
(
instance
)
+
"config/view"
;
String
result
=
restTemplate
.
getForEntity
(
url
,
String
.
class
).
getBody
();
...
...
@@ -61,7 +62,7 @@ public class ServiceController {
}
public
static
RouterEntity
routes
(
Instance
instance
,
String
routeServiceIds
)
{
String
url
=
getUrl
(
instance
)
+
"
/
router/routes"
;
String
url
=
getUrl
(
instance
)
+
"router/routes"
;
String
result
=
restTemplate
.
postForEntity
(
url
,
routeServiceIds
,
String
.
class
).
getBody
();
...
...
@@ -70,7 +71,7 @@ public class ServiceController {
}
public
static
List
<
ResultEntity
>
versionUpdate
(
String
serviceId
,
String
version
)
{
String
url
=
getUrl
()
+
"
/
console/version/update/"
+
serviceId
;
String
url
=
getUrl
()
+
"console/version/update/"
+
serviceId
;
String
result
=
restTemplate
.
postForEntity
(
url
,
version
,
String
.
class
).
getBody
();
...
...
@@ -79,7 +80,7 @@ public class ServiceController {
}
public
static
String
versionUpdate
(
Instance
instance
,
String
version
)
{
String
url
=
getUrl
(
instance
)
+
"
/
version/update"
;
String
url
=
getUrl
(
instance
)
+
"version/update"
;
String
result
=
restTemplate
.
postForEntity
(
url
,
version
,
String
.
class
).
getBody
();
...
...
@@ -92,7 +93,7 @@ public class ServiceController {
}
public
static
List
<
ResultEntity
>
versionClear
(
String
serviceId
)
{
String
url
=
getUrl
()
+
"
/
console/version/clear/"
+
serviceId
;
String
url
=
getUrl
()
+
"console/version/clear/"
+
serviceId
;
String
result
=
restTemplate
.
postForEntity
(
url
,
null
,
String
.
class
).
getBody
();
...
...
@@ -101,7 +102,7 @@ public class ServiceController {
}
public
static
String
versionClear
(
Instance
instance
)
{
String
url
=
getUrl
(
instance
)
+
"
/
version/clear"
;
String
url
=
getUrl
(
instance
)
+
"version/clear"
;
String
result
=
restTemplate
.
postForEntity
(
url
,
null
,
String
.
class
).
getBody
();
...
...
@@ -114,7 +115,7 @@ public class ServiceController {
}
public
static
String
remoteConfigUpdate
(
String
group
,
String
serviceId
,
String
config
)
{
String
url
=
getUrl
()
+
"
/
console/remote-config/update/"
+
group
+
"/"
+
serviceId
;
String
url
=
getUrl
()
+
"console/remote-config/update/"
+
group
+
"/"
+
serviceId
;
// 解决中文乱码
HttpHeaders
headers
=
new
HttpHeaders
();
...
...
@@ -132,7 +133,7 @@ public class ServiceController {
}
public
static
List
<
ResultEntity
>
configUpdate
(
String
serviceId
,
String
config
)
{
String
url
=
getUrl
()
+
"
/
console/config/update-sync/"
+
serviceId
;
String
url
=
getUrl
()
+
"console/config/update-sync/"
+
serviceId
;
// 解决中文乱码
HttpHeaders
headers
=
new
HttpHeaders
();
...
...
@@ -146,7 +147,7 @@ public class ServiceController {
}
public
static
String
configUpdate
(
Instance
instance
,
String
config
)
{
String
url
=
getUrl
(
instance
)
+
"
/
config/update-sync"
;
String
url
=
getUrl
(
instance
)
+
"config/update-sync"
;
// 解决中文乱码
HttpHeaders
headers
=
new
HttpHeaders
();
...
...
@@ -164,7 +165,7 @@ public class ServiceController {
}
public
static
String
remoteConfigClear
(
String
group
,
String
serviceId
)
{
String
url
=
getUrl
()
+
"
/
console/remote-config/clear/"
+
group
+
"/"
+
serviceId
;
String
url
=
getUrl
()
+
"console/remote-config/clear/"
+
group
+
"/"
+
serviceId
;
String
result
=
restTemplate
.
postForEntity
(
url
,
null
,
String
.
class
).
getBody
();
...
...
@@ -177,7 +178,7 @@ public class ServiceController {
}
public
static
List
<
ResultEntity
>
configClear
(
String
serviceId
)
{
String
url
=
getUrl
()
+
"
/
console/config/clear/"
+
serviceId
;
String
url
=
getUrl
()
+
"console/config/clear/"
+
serviceId
;
String
result
=
restTemplate
.
postForEntity
(
url
,
null
,
String
.
class
).
getBody
();
...
...
@@ -186,7 +187,7 @@ public class ServiceController {
}
public
static
String
configClear
(
Instance
instance
)
{
String
url
=
getUrl
(
instance
)
+
"
/
config/clear"
;
String
url
=
getUrl
(
instance
)
+
"config/clear"
;
String
result
=
restTemplate
.
postForEntity
(
url
,
null
,
String
.
class
).
getBody
();
...
...
@@ -199,7 +200,7 @@ public class ServiceController {
}
public
static
String
remoteConfigView
(
String
group
,
String
serviceId
)
{
String
url
=
getUrl
()
+
"
/
console/remote-config/view/"
+
group
+
"/"
+
serviceId
;
String
url
=
getUrl
()
+
"console/remote-config/view/"
+
group
+
"/"
+
serviceId
;
String
result
=
restTemplate
.
getForEntity
(
url
,
String
.
class
).
getBody
();
...
...
@@ -216,7 +217,7 @@ public class ServiceController {
}
private
static
String
getUrl
(
Instance
instance
)
{
String
url
=
"http://"
+
instance
.
getHost
()
+
":"
+
instance
.
getPort
();
String
url
=
"http://"
+
instance
.
getHost
()
+
":"
+
instance
.
getPort
()
+
UrlUtil
.
formatContextPath
(
instance
.
getContextPath
())
;
return
url
;
}
...
...
discovery-console-desktop/src/main/java/com/nepxion/discovery/console/desktop/entity/Instance.java
View file @
d9f0952b
...
...
@@ -47,6 +47,12 @@ public class Instance extends InstanceEntity {
this
.
dynamicRule
=
dynamicRule
;
}
public
String
getContextPath
()
{
Map
<
String
,
String
>
metadata
=
getMetadata
();
return
metadata
.
get
(
DiscoveryConstant
.
SPRING_APPLICATION_CONTEXT_PATH
);
}
public
String
getFilter
()
{
Map
<
String
,
String
>
metadata
=
getMetadata
();
String
filterKey
=
metadata
.
get
(
DiscoveryConstant
.
SPRING_APPLICATION_GROUP_KEY
);
...
...
discovery-console/src/main/java/com/nepxion/discovery/console/rest/AbstractRestInvoker.java
View file @
d9f0952b
...
...
@@ -24,6 +24,7 @@ import org.springframework.web.client.RestTemplate;
import
com.nepxion.discovery.common.constant.DiscoveryConstant
;
import
com.nepxion.discovery.common.entity.ResultEntity
;
import
com.nepxion.discovery.common.util.UrlUtil
;
import
com.nepxion.discovery.console.handler.ConsoleErrorHandler
;
public
abstract
class
AbstractRestInvoker
{
...
...
@@ -46,11 +47,13 @@ public abstract class AbstractRestInvoker {
List
<
ResultEntity
>
resultEntityList
=
new
ArrayList
<
ResultEntity
>();
for
(
ServiceInstance
serviceInstance
:
serviceInstances
)
{
Map
<
String
,
String
>
metadata
=
serviceInstance
.
getMetadata
();
String
host
=
serviceInstance
.
getHost
();
int
port
=
serviceInstance
.
getPort
();
String
url
=
getUrl
(
host
,
port
);
String
result
=
null
;
String
contextPath
=
metadata
.
get
(
DiscoveryConstant
.
SPRING_APPLICATION_CONTEXT_PATH
);
String
url
=
"http://"
+
host
+
":"
+
port
+
UrlUtil
.
formatContextPath
(
contextPath
)
+
getSuffixPath
()
;
String
result
=
null
;
try
{
checkPermission
(
serviceInstance
);
...
...
@@ -104,7 +107,7 @@ public abstract class AbstractRestInvoker {
protected
abstract
String
getInfo
();
protected
abstract
String
get
Url
(
String
host
,
int
port
);
protected
abstract
String
get
SuffixPath
(
);
protected
abstract
String
doRest
(
String
url
);
...
...
discovery-console/src/main/java/com/nepxion/discovery/console/rest/ConfigClearRestInvoker.java
View file @
d9f0952b
...
...
@@ -25,8 +25,8 @@ public class ConfigClearRestInvoker extends AbstractRestInvoker {
}
@Override
protected
String
get
Url
(
String
host
,
int
port
)
{
return
"
http://"
+
host
+
":"
+
port
+
"/
config/clear"
;
protected
String
get
SuffixPath
(
)
{
return
"config/clear"
;
}
@Override
...
...
discovery-console/src/main/java/com/nepxion/discovery/console/rest/ConfigUpdateRestInvoker.java
View file @
d9f0952b
...
...
@@ -34,8 +34,8 @@ public class ConfigUpdateRestInvoker extends AbstractRestInvoker {
}
@Override
protected
String
get
Url
(
String
host
,
int
port
)
{
return
"
http://"
+
host
+
":"
+
port
+
"/
config/update-"
+
(
async
?
"async"
:
"sync"
);
protected
String
get
SuffixPath
(
)
{
return
"config/update-"
+
(
async
?
"async"
:
"sync"
);
}
@Override
...
...
discovery-console/src/main/java/com/nepxion/discovery/console/rest/VersionClearRestInvoker.java
View file @
d9f0952b
...
...
@@ -29,8 +29,8 @@ public class VersionClearRestInvoker extends AbstractRestInvoker {
}
@Override
protected
String
get
Url
(
String
host
,
int
port
)
{
return
"
http://"
+
host
+
":"
+
port
+
"/
version/clear"
;
protected
String
get
SuffixPath
(
)
{
return
"version/clear"
;
}
@Override
...
...
discovery-console/src/main/java/com/nepxion/discovery/console/rest/VersionUpdateRestInvoker.java
View file @
d9f0952b
...
...
@@ -29,8 +29,8 @@ public class VersionUpdateRestInvoker extends AbstractRestInvoker {
}
@Override
protected
String
get
Url
(
String
host
,
int
port
)
{
return
"
http://"
+
host
+
":"
+
port
+
"/
version/update"
;
protected
String
get
SuffixPath
(
)
{
return
"version/update"
;
}
@Override
...
...
discovery-plugin-admin-center/src/main/java/com/nepxion/discovery/plugin/admincenter/endpoint/RouterEndpoint.java
View file @
d9f0952b
...
...
@@ -34,6 +34,7 @@ import org.springframework.web.client.RestTemplate;
import
com.nepxion.discovery.common.constant.DiscoveryConstant
;
import
com.nepxion.discovery.common.entity.RouterEntity
;
import
com.nepxion.discovery.common.exception.DiscoveryException
;
import
com.nepxion.discovery.common.util.UrlUtil
;
import
com.nepxion.discovery.plugin.framework.adapter.PluginAdapter
;
@RestController
...
...
@@ -73,10 +74,10 @@ public class RouterEndpoint {
return
getRouterEntityList
(
routeServiceId
);
}
@RequestMapping
(
path
=
"/route/{routeServiceId}/{routeHost}/{routePort}"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
path
=
"/route/{routeServiceId}/{routeHost}/{routePort}
/{routeContextPath}
"
,
method
=
RequestMethod
.
GET
)
@ApiOperation
(
value
=
"获取指定节点(根据IP和端口)可访问其他节点(根据服务名)的路由信息列表"
,
notes
=
""
,
response
=
List
.
class
,
httpMethod
=
"GET"
)
public
List
<
RouterEntity
>
route
(
@PathVariable
(
value
=
"routeServiceId"
)
@ApiParam
(
value
=
"目标服务名"
,
required
=
true
)
String
routeServiceId
,
@PathVariable
(
value
=
"routeHost"
)
@ApiParam
(
value
=
"目标服务所在机器的IP地址"
,
required
=
true
)
String
routeHost
,
@PathVariable
(
value
=
"routePort"
)
@ApiParam
(
value
=
"目标服务所在机器的端口号"
,
required
=
true
)
int
routePort
)
{
return
getRouterEntityList
(
routeServiceId
,
routeHost
,
routePort
);
public
List
<
RouterEntity
>
route
(
@PathVariable
(
value
=
"routeServiceId"
)
@ApiParam
(
value
=
"目标服务名"
,
required
=
true
)
String
routeServiceId
,
@PathVariable
(
value
=
"routeHost"
)
@ApiParam
(
value
=
"目标服务所在机器的IP地址"
,
required
=
true
)
String
routeHost
,
@PathVariable
(
value
=
"routePort"
)
@ApiParam
(
value
=
"目标服务所在机器的端口号"
,
required
=
true
)
int
routePort
,
@PathVariable
(
value
=
"routeContextPath"
)
@ApiParam
(
value
=
"目标服务的调用路径前缀"
,
required
=
true
,
defaultValue
=
"/"
)
String
routeContextPath
)
{
return
getRouterEntityList
(
routeServiceId
,
routeHost
,
routePort
,
routeContextPath
);
}
@RequestMapping
(
path
=
"/routes"
,
method
=
RequestMethod
.
POST
)
...
...
@@ -98,12 +99,14 @@ public class RouterEndpoint {
String
version
=
pluginAdapter
.
getVersion
();
String
host
=
pluginAdapter
.
getHost
();
int
port
=
pluginAdapter
.
getPort
();
String
contextPath
=
pluginAdapter
.
getContextPath
();
RouterEntity
routerEntity
=
new
RouterEntity
();
routerEntity
.
setServiceId
(
serviceId
);
routerEntity
.
setVersion
(
version
);
routerEntity
.
setHost
(
host
);
routerEntity
.
setPort
(
port
);
routerEntity
.
setContextPath
(
contextPath
);
return
routerEntity
;
}
...
...
@@ -128,12 +131,14 @@ public class RouterEndpoint {
String
version
=
metadata
.
get
(
DiscoveryConstant
.
VERSION
);
String
host
=
instance
.
getHost
();
int
port
=
instance
.
getPort
();
String
contextPath
=
metadata
.
get
(
DiscoveryConstant
.
SPRING_APPLICATION_CONTEXT_PATH
);
RouterEntity
routerEntity
=
new
RouterEntity
();
routerEntity
.
setServiceId
(
serviceId
);
routerEntity
.
setVersion
(
version
);
routerEntity
.
setHost
(
host
);
routerEntity
.
setPort
(
port
);
routerEntity
.
setContextPath
(
contextPath
);
routerEntityList
.
add
(
routerEntity
);
}
...
...
@@ -142,8 +147,8 @@ public class RouterEndpoint {
}
@SuppressWarnings
(
"unchecked"
)
public
List
<
RouterEntity
>
getRouterEntityList
(
String
routeServiceId
,
String
routeHost
,
int
routePort
)
{
String
url
=
"http://"
+
routeHost
+
":"
+
routePort
+
"/
router/instances/"
+
routeServiceId
;
public
List
<
RouterEntity
>
getRouterEntityList
(
String
routeServiceId
,
String
routeHost
,
int
routePort
,
String
routeContextPath
)
{
String
url
=
"http://"
+
routeHost
+
":"
+
routePort
+
UrlUtil
.
formatContextPath
(
routeContextPath
)
+
"
router/instances/"
+
routeServiceId
;
List
<
Map
<
String
,
?>>
instanceList
=
null
;
try
{
...
...
@@ -163,12 +168,14 @@ public class RouterEndpoint {
String
version
=
metadata
.
get
(
DiscoveryConstant
.
VERSION
);
String
host
=
instance
.
get
(
DiscoveryConstant
.
HOST
).
toString
();
Integer
port
=
(
Integer
)
instance
.
get
(
DiscoveryConstant
.
PORT
);
String
contextPath
=
metadata
.
get
(
DiscoveryConstant
.
SPRING_APPLICATION_CONTEXT_PATH
);
RouterEntity
routerEntity
=
new
RouterEntity
();
routerEntity
.
setServiceId
(
serviceId
);
routerEntity
.
setVersion
(
version
);
routerEntity
.
setHost
(
host
);
routerEntity
.
setPort
(
port
);
routerEntity
.
setContextPath
(
contextPath
);
routerEntityList
.
add
(
routerEntity
);
}
...
...
@@ -204,8 +211,9 @@ public class RouterEndpoint {
for
(
RouterEntity
routerEntity
:
routerEntityList
)
{
String
routeHost
=
routerEntity
.
getHost
();
int
routePort
=
routerEntity
.
getPort
();
String
routeContextPath
=
routerEntity
.
getContextPath
();
route
(
routerEntity
,
serviceId
,
routeHost
,
routePort
);
route
(
routerEntity
,
serviceId
,
routeHost
,
routePort
,
routeContextPath
);
retrieveRouterEntityList
(
routerEntityMap
,
routerDepth
).
addAll
(
routerEntity
.
getNexts
());
}
...
...
@@ -224,8 +232,8 @@ public class RouterEndpoint {
}
}
private
void
route
(
RouterEntity
routerEntity
,
String
routeServiceId
,
String
routeHost
,
int
routePort
)
{
List
<
RouterEntity
>
routerEntityList
=
getRouterEntityList
(
routeServiceId
,
routeHost
,
routePort
);
private
void
route
(
RouterEntity
routerEntity
,
String
routeServiceId
,
String
routeHost
,
int
routePort
,
String
routeContextPath
)
{
List
<
RouterEntity
>
routerEntityList
=
getRouterEntityList
(
routeServiceId
,
routeHost
,
routePort
,
routeContextPath
);
if
(
CollectionUtils
.
isNotEmpty
(
routerEntityList
))
{
routerEntity
.
getNexts
().
addAll
(
routerEntityList
);
}
...
...
discovery-plugin-framework-consul/src/main/java/com/nepxion/discovery/plugin/framework/context/ConsulApplicationContextInitializer.java
View file @
d9f0952b
...
...
@@ -40,6 +40,7 @@ public class ConsulApplicationContextInitializer extends PluginApplicationContex
tags
.
add
(
DiscoveryConstant
.
SPRING_APPLICATION_DISCOVERY_CONTROL_ENABLED
+
"="
+
PluginContextAware
.
isDiscoveryControlEnabled
(
environment
));
tags
.
add
(
DiscoveryConstant
.
SPRING_APPLICATION_CONFIG_REST_CONTROL_ENABLED
+
"="
+
PluginContextAware
.
isConfigRestControlEnabled
(
environment
));
tags
.
add
(
DiscoveryConstant
.
SPRING_APPLICATION_GROUP_KEY
+
"="
+
PluginContextAware
.
getGroupKey
(
environment
));
tags
.
add
(
DiscoveryConstant
.
SPRING_APPLICATION_CONTEXT_PATH
+
"="
+
PluginContextAware
.
getContextPath
(
environment
));
return
bean
;
}
else
{
...
...
discovery-plugin-framework-eureka/src/main/java/com/nepxion/discovery/plugin/framework/context/EurekaApplicationContextInitializer.java
View file @
d9f0952b
...
...
@@ -40,6 +40,7 @@ public class EurekaApplicationContextInitializer extends PluginApplicationContex
metadataMap
.
put
(
DiscoveryConstant
.
SPRING_APPLICATION_DISCOVERY_CONTROL_ENABLED
,
PluginContextAware
.
isDiscoveryControlEnabled
(
environment
).
toString
());
metadataMap
.
put
(
DiscoveryConstant
.
SPRING_APPLICATION_CONFIG_REST_CONTROL_ENABLED
,
PluginContextAware
.
isConfigRestControlEnabled
(
environment
).
toString
());
metadataMap
.
put
(
DiscoveryConstant
.
SPRING_APPLICATION_GROUP_KEY
,
PluginContextAware
.
getGroupKey
(
environment
));
metadataMap
.
put
(
DiscoveryConstant
.
SPRING_APPLICATION_CONTEXT_PATH
,
PluginContextAware
.
getContextPath
(
environment
));
return
bean
;
}
else
{
...
...
discovery-plugin-framework-zookeeper/src/main/java/com/nepxion/discovery/plugin/framework/context/ZookeeperApplicationContextInitializer.java
View file @
d9f0952b
...
...
@@ -40,6 +40,7 @@ public class ZookeeperApplicationContextInitializer extends PluginApplicationCon
metadata
.
put
(
DiscoveryConstant
.
SPRING_APPLICATION_DISCOVERY_CONTROL_ENABLED
,
PluginContextAware
.
isDiscoveryControlEnabled
(
environment
).
toString
());
metadata
.
put
(
DiscoveryConstant
.
SPRING_APPLICATION_CONFIG_REST_CONTROL_ENABLED
,
PluginContextAware
.
isConfigRestControlEnabled
(
environment
).
toString
());
metadata
.
put
(
DiscoveryConstant
.
SPRING_APPLICATION_GROUP_KEY
,
PluginContextAware
.
getGroupKey
(
environment
));
metadata
.
put
(
DiscoveryConstant
.
SPRING_APPLICATION_CONTEXT_PATH
,
PluginContextAware
.
getContextPath
(
environment
));
return
bean
;
}
else
{
...
...
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/adapter/AbstractPluginAdapter.java
View file @
d9f0952b
...
...
@@ -68,6 +68,11 @@ public abstract class AbstractPluginAdapter implements PluginAdapter {
}
@Override
public
String
getContextPath
()
{
return
getMetadata
().
get
(
DiscoveryConstant
.
SPRING_APPLICATION_CONTEXT_PATH
);
}
@Override
public
Map
<
String
,
String
>
getMetadata
()
{
return
registration
.
getMetadata
();
}
...
...
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/adapter/PluginAdapter.java
View file @
d9f0952b
...
...
@@ -23,6 +23,8 @@ public interface PluginAdapter {
int
getPort
();
String
getContextPath
();
Map
<
String
,
String
>
getMetadata
();
String
getVersion
();
...
...
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/context/PluginContextAware.java
View file @
d9f0952b
...
...
@@ -109,6 +109,10 @@ public class PluginContextAware implements ApplicationContextAware {
return
getGroupKey
(
environment
);
}
public
String
getContextPath
()
{
return
getContextPath
(
environment
);
}
public
static
Boolean
isRegisterControlEnabled
(
Environment
environment
)
{
return
environment
.
getProperty
(
DiscoveryConstant
.
SPRING_APPLICATION_REGISTER_CONTROL_ENABLED
,
Boolean
.
class
,
Boolean
.
TRUE
);
}
...
...
@@ -132,4 +136,8 @@ public class PluginContextAware implements ApplicationContextAware {
public
static
String
getGroupKey
(
Environment
environment
)
{
return
environment
.
getProperty
(
DiscoveryConstant
.
SPRING_APPLICATION_GROUP_KEY
,
String
.
class
,
DiscoveryConstant
.
GROUP
);
}
public
static
String
getContextPath
(
Environment
environment
)
{
return
environment
.
getProperty
(
DiscoveryConstant
.
SPRING_APPLICATION_CONTEXT_PATH
,
String
.
class
,
"/"
);
}
}
\ No newline at end of file
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/feign/AFeign.java
View file @
d9f0952b
...
...
@@ -15,6 +15,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.RequestMethod
;
@FeignClient
(
value
=
"discovery-springcloud-example-a"
)
// Context-patch一旦被设置,在Feign也要带上context-path,外部Postman调用网关或者服务路径也要带context-path
// @FeignClient(value = "discovery-springcloud-example-a/nepxion")
public
interface
AFeign
{
@RequestMapping
(
path
=
"/invoke"
,
method
=
RequestMethod
.
POST
)
String
invoke
(
@RequestBody
String
value
);
...
...
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/feign/BFeign.java
View file @
d9f0952b
...
...
@@ -15,6 +15,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.RequestMethod
;
@FeignClient
(
value
=
"discovery-springcloud-example-b"
)
// Context-patch一旦被设置,在Feign也要带上context-path,外部Postman调用网关或者服务路径也要带context-path
// @FeignClient(value = "discovery-springcloud-example-b/nepxion")
public
interface
BFeign
{
@RequestMapping
(
path
=
"/invoke"
,
method
=
RequestMethod
.
POST
)
String
invoke
(
@RequestBody
String
value
);
...
...
discovery-springcloud-example-service/src/main/java/com/nepxion/discovery/plugin/example/service/feign/CFeign.java
View file @
d9f0952b
...
...
@@ -15,6 +15,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.RequestMethod
;
@FeignClient
(
value
=
"discovery-springcloud-example-c"
)
// Context-patch一旦被设置,在Feign也要带上context-path,外部Postman调用网关或者服务路径也要带context-path
// @FeignClient(value = "discovery-springcloud-example-c/nepxion")
public
interface
CFeign
{
@RequestMapping
(
path
=
"/invoke"
,
method
=
RequestMethod
.
POST
)
String
invoke
(
@RequestBody
String
value
);
...
...
discovery-springcloud-example-service/src/main/resources/bootstrap.properties
View file @
d9f0952b
# Spring cloud config
# server.servlet.context-path=/nepxion
# Eureka config
eureka.client.serviceUrl.defaultZone
=
http://localhost:9528/eureka/
...
...
@@ -52,6 +53,8 @@ management.security.enabled=false
# 为微服务归类的Key,一般通过group字段来归类,例如eureka.instance.metadataMap.group=xxx-group或者eureka.instance.metadataMap.application=xxx-application。缺失则默认为group
# spring.application.group.key=group
# spring.application.group.key=application
# 内置Rest调用路径的前缀,当配置了server.context-path或者server.servlet.context-path时候,需要同步配置下面的值,务必保持一致
# spring.application.context-path=/nepxion
# Plugin strategy config
# 开启和关闭用户自定义和编程灰度路由策略的控制,例如用户根据业务参数的不同,负载均衡到不同的服务器。缺失则默认为true
...
...
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