Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-boot-admin
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
spring-boot-admin
Commits
f0002da6
Commit
f0002da6
authored
Jul 25, 2018
by
赵天增
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
补充注释
parent
74f29998
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
4 deletions
+33
-4
InstanceDiscoveryListener.java
...min/server/cloud/discovery/InstanceDiscoveryListener.java
+29
-4
InstanceRegistry.java
...ecentric/boot/admin/server/services/InstanceRegistry.java
+4
-0
No files found.
spring-boot-admin-server-cloud/src/main/java/de/codecentric/boot/admin/server/cloud/discovery/InstanceDiscoveryListener.java
View file @
f0002da6
...
...
@@ -27,6 +27,7 @@ import reactor.core.publisher.Mono;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.Set
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -43,6 +44,8 @@ import org.springframework.util.PatternMatchUtils;
/**
* Listener for Heartbeats events to publish all services to the instance registry.
*
* 监听Heartbeats事件以将所有服务发布到实例注册表。
*
* @author Johannes Edmeier
*/
public
class
InstanceDiscoveryListener
{
...
...
@@ -89,6 +92,10 @@ public class InstanceDiscoveryListener {
discoverIfNeeded
(
event
.
getValue
());
}
/**
* 监听eureka的心跳
* @param event
*/
@EventListener
public
void
onApplicationEvent
(
HeartbeatEvent
event
)
{
discoverIfNeeded
(
event
.
getValue
());
...
...
@@ -101,13 +108,31 @@ public class InstanceDiscoveryListener {
}
protected
void
discover
()
{
// 开始进行发现逻辑,获取所有注册上去的服务
Flux
.
fromIterable
(
discoveryClient
.
getServices
())
// 是否需要进行注册,可以控制有的服务不被发现
.
filter
(
this
::
shouldRegisterService
)
.
flatMapIterable
(
discoveryClient:
:
getInstances
)
.
flatMap
(
this
::
registerInstance
)
.
flatMapIterable
(
new
Function
<
String
,
Iterable
<
ServiceInstance
>>()
{
@Override
public
Iterable
<
ServiceInstance
>
apply
(
String
s
)
{
return
discoveryClient
.
getInstances
(
s
);
}
})
.
flatMap
(
new
Function
<
ServiceInstance
,
Mono
<
InstanceId
>>()
{
@Override
public
Mono
<
InstanceId
>
apply
(
ServiceInstance
serviceInstance
)
{
return
registerInstance
(
serviceInstance
);
}
})
.
collect
(
Collectors
.
toSet
())
.
flatMap
(
this
::
removeStaleInstances
)
.
subscribe
(
v
->
{
},
ex
->
log
.
error
(
"Unexpected error."
,
ex
));
.
flatMap
(
new
Function
<
Set
<
InstanceId
>,
Mono
<
Void
>>()
{
@Override
public
Mono
<
Void
>
apply
(
Set
<
InstanceId
>
objects
)
{
return
removeStaleInstances
(
objects
);
}
})
.
subscribe
(
v
->
{
},
ex
->
log
.
error
(
"Unexpected error."
,
ex
));
}
protected
Mono
<
Void
>
removeStaleInstances
(
Set
<
InstanceId
>
registeredInstanceIds
)
{
...
...
spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/server/services/InstanceRegistry.java
View file @
f0002da6
...
...
@@ -48,12 +48,16 @@ public class InstanceRegistry {
*/
public
Mono
<
InstanceId
>
register
(
Registration
registration
)
{
Assert
.
notNull
(
registration
,
"'registration' must not be null"
);
// 通过某种算法生成InstanceId
InstanceId
id
=
generator
.
generateId
(
registration
);
Assert
.
notNull
(
id
,
"'id' must not be null"
);
// 然后更新这个id对应的实例信息
return
repository
.
compute
(
id
,
(
key
,
instance
)
->
{
// 如果这个对应的实例信息为空,会创建一个信息实例上去
if
(
instance
==
null
)
{
instance
=
Instance
.
create
(
key
);
}
// 然后把注册实例注册上去
return
Mono
.
just
(
instance
.
register
(
registration
));
}).
map
(
Instance:
:
getId
);
}
...
...
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