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
828f2f27
Commit
828f2f27
authored
Jun 28, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
测试用例,增加Route接口
parent
f2803837
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
16 deletions
+28
-16
discovery-springcloud-example-a/src/main/java/com/nepxion/discovery/plugin/example/DiscoveryApplication.java
+0
-2
discovery-springcloud-example-a/src/main/java/com/nepxion/discovery/plugin/example/controller/DiscoveryController.java
+28
-14
No files found.
discovery-springcloud-example-a/src/main/java/com/nepxion/discovery/plugin/example/DiscoveryApplication.java
View file @
828f2f27
...
...
@@ -12,7 +12,6 @@ package com.nepxion.discovery.plugin.example;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.cloud.client.discovery.EnableDiscoveryClient
;
import
org.springframework.cloud.client.loadbalancer.LoadBalanced
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.web.client.RestTemplate
;
...
...
@@ -28,7 +27,6 @@ public class DiscoveryApplication {
}
@Bean
@LoadBalanced
public
RestTemplate
restTemplate
()
{
return
new
RestTemplate
();
}
...
...
discovery-springcloud-example-a/src/main/java/com/nepxion/discovery/plugin/example/controller/DiscoveryController.java
View file @
828f2f27
...
...
@@ -13,6 +13,7 @@ import java.util.ArrayList;
import
java.util.List
;
import
java.util.Map
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.cloud.client.ServiceInstance
;
...
...
@@ -51,22 +52,35 @@ public class DiscoveryController {
// 获取B服务的实例列表
List
<
ServiceInstance
>
bInstances
=
instances
();
// 获取C服务的实例列表
List
<
Map
<
String
,
?>>
cInstances
=
restTemplate
.
getForEntity
(
"http://discovery-springcloud-example-b/instances"
,
List
.
class
).
getBody
();
String
aInfo
=
aServiceId
.
toLowerCase
()
+
"["
+
aEurekaVersion
+
"]"
;
for
(
ServiceInstance
bInstance
:
bInstances
)
{
String
bServiceId
=
bInstance
.
getServiceId
().
toLowerCase
();
String
bEurekaVersion
=
bInstance
.
getMetadata
().
get
(
PluginConstant
.
VERSION
);
String
bInfo
=
bServiceId
+
"["
+
bEurekaVersion
+
"]"
;
for
(
Map
<
String
,
?>
cInstance
:
cInstances
)
{
String
cServiceId
=
cInstance
.
get
(
"serviceId"
).
toString
().
toLowerCase
();
String
cEurekaVersion
=
((
Map
<
String
,
String
>)
cInstance
.
get
(
"metadata"
)).
get
(
PluginConstant
.
VERSION
);
String
cInfo
=
cServiceId
+
"["
+
cEurekaVersion
+
"]"
;
StringBuilder
stringBuilder
=
new
StringBuilder
();
routes
.
add
(
stringBuilder
.
append
(
aInfo
).
append
(
"->"
).
append
(
bInfo
).
append
(
"->"
).
append
(
cInfo
).
toString
());
if
(
CollectionUtils
.
isNotEmpty
(
bInstances
))
{
for
(
ServiceInstance
bInstance
:
bInstances
)
{
String
bServiceId
=
bInstance
.
getServiceId
().
toLowerCase
();
String
bEurekaVersion
=
bInstance
.
getMetadata
().
get
(
PluginConstant
.
VERSION
);
String
bInfo
=
bServiceId
+
"["
+
bEurekaVersion
+
"]"
;
String
bHost
=
bInstance
.
getHost
();
int
bPort
=
bInstance
.
getPort
();
// 获取C服务的实例列表
List
<
Map
<
String
,
?>>
cInstances
=
restTemplate
.
getForEntity
(
"http://"
+
bHost
+
":"
+
bPort
+
"/instances"
,
List
.
class
).
getBody
();
if
(
CollectionUtils
.
isNotEmpty
(
cInstances
))
{
for
(
Map
<
String
,
?>
cInstance
:
cInstances
)
{
String
cServiceId
=
cInstance
.
get
(
"serviceId"
).
toString
().
toLowerCase
();
String
cEurekaVersion
=
((
Map
<
String
,
String
>)
cInstance
.
get
(
"metadata"
)).
get
(
PluginConstant
.
VERSION
);
String
cInfo
=
cServiceId
+
"["
+
cEurekaVersion
+
"]"
;
StringBuilder
stringBuilder
=
new
StringBuilder
();
routes
.
add
(
stringBuilder
.
append
(
aInfo
).
append
(
"->"
).
append
(
bInfo
).
append
(
"->"
).
append
(
cInfo
).
toString
());
}
}
else
{
StringBuilder
stringBuilder
=
new
StringBuilder
();
routes
.
add
(
stringBuilder
.
append
(
aInfo
).
append
(
"->"
).
append
(
bInfo
).
toString
());
}
}
}
else
{
StringBuilder
stringBuilder
=
new
StringBuilder
();
routes
.
add
(
stringBuilder
.
append
(
aInfo
).
toString
());
}
return
routes
;
...
...
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