Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-cloud-netflix
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-cloud-netflix
Commits
8b2254a3
Commit
8b2254a3
authored
Nov 05, 2014
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Register a HealthCheckHandler on DiscoveryClient if there is a HealthCheckHandler bean registered.
fixes gh-50
parent
c752cc31
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
0 deletions
+22
-0
EurekaClientConfiguration.java
...ework/cloud/netflix/eureka/EurekaClientConfiguration.java
+9
-0
Application.java
...ingframework/cloud/netflix/eureka/sample/Application.java
+13
-0
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/eureka/EurekaClientConfiguration.java
View file @
8b2254a3
...
...
@@ -17,6 +17,7 @@ package org.springframework.cloud.netflix.eureka;
import
javax.annotation.PreDestroy
;
import
com.netflix.appinfo.HealthCheckHandler
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -62,6 +63,9 @@ public class EurekaClientConfiguration implements SmartLifecycle, Ordered {
@Autowired
private
EurekaInstanceConfigBean
instanceConfig
;
@Autowired
(
required
=
false
)
private
HealthCheckHandler
healthCheckHandler
;
@PreDestroy
public
void
close
()
{
logger
.
info
(
"Removing application {} from eureka"
,
instanceConfig
.
getAppname
());
...
...
@@ -78,9 +82,14 @@ public class EurekaClientConfiguration implements SmartLifecycle, Ordered {
//because of containerPortInitializer below
if
(!
running
&&
instanceConfig
.
getNonSecurePort
()
>
0
)
{
discoveryManagerIntitializer
().
init
();
logger
.
info
(
"Registering application {} with eureka with status {}"
,
instanceConfig
.
getAppname
(),
instanceConfig
.
getInitialStatus
());
ApplicationInfoManager
.
getInstance
().
setInstanceStatus
(
instanceConfig
.
getInitialStatus
());
if
(
healthCheckHandler
!=
null
)
{
DiscoveryManager
.
getInstance
().
getDiscoveryClient
().
registerHealthCheck
(
healthCheckHandler
);
}
running
=
true
;
}
}
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/eureka/sample/Application.java
View file @
8b2254a3
package
org
.
springframework
.
cloud
.
netflix
.
eureka
.
sample
;
import
com.netflix.appinfo.HealthCheckHandler
;
import
com.netflix.appinfo.InstanceInfo
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.cloud.netflix.eureka.EnableEurekaClient
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
...
@@ -15,6 +18,16 @@ import org.springframework.web.bind.annotation.RestController;
@EnableEurekaClient
public
class
Application
{
@Bean
public
HealthCheckHandler
healthCheckHandler
()
{
return
new
HealthCheckHandler
()
{
@Override
public
InstanceInfo
.
InstanceStatus
getStatus
(
InstanceInfo
.
InstanceStatus
currentStatus
)
{
return
InstanceInfo
.
InstanceStatus
.
UP
;
}
};
}
@RequestMapping
(
"/"
)
public
String
home
()
{
return
"Hello world"
;
...
...
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