Commit 8b2254a3 by Spencer Gibb

Register a HealthCheckHandler on DiscoveryClient if there is a HealthCheckHandler bean registered.

fixes gh-50
parent c752cc31
......@@ -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;
}
}
......
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";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment