Allow to not register a healthcheck.

Useful for development.
This commit is contained in:
Spencer Gibb
2016-03-21 15:05:06 -06:00
parent a6803340c2
commit e4fb366009
3 changed files with 22 additions and 7 deletions

View File

@@ -125,6 +125,11 @@ public class ConsulDiscoveryProperties {
*/
private boolean register = true;
/**
* Register health check in consul. Useful during development of a service.
*/
private boolean registerHealthCheck = true;
@SuppressWarnings("unused")
private ConsulDiscoveryProperties() {}

View File

@@ -96,13 +96,15 @@ public class ConsulLifecycle extends AbstractDiscoveryLifecycle {
service.setPort(properties.getPort());
}
Integer checkPort;
if (shouldRegisterManagement()) {
checkPort = getManagementPort();
} else {
checkPort = service.getPort();
if (this.properties.isRegisterHealthCheck()) {
Integer checkPort;
if (shouldRegisterManagement()) {
checkPort = getManagementPort();
} else {
checkPort = service.getPort();
}
service.setCheck(createCheck(checkPort));
}
service.setCheck(createCheck(checkPort));
register(service);
}

View File

@@ -16,6 +16,7 @@
package org.springframework.cloud.consul.discovery;
import java.util.List;
import java.util.Map;
import org.junit.FixMethodOrder;
@@ -33,8 +34,10 @@ import org.springframework.context.annotation.Import;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.ecwid.consul.v1.ConsulClient;
import com.ecwid.consul.v1.QueryParams;
import com.ecwid.consul.v1.Response;
import com.ecwid.consul.v1.agent.model.Service;
import com.ecwid.consul.v1.health.model.Check;
import static org.junit.Assert.assertThat;
import static org.hamcrest.Matchers.*;
@@ -49,7 +52,8 @@ import static org.hamcrest.Matchers.*;
"spring.cloud.consul.discovery.instanceId=myTestService1",
"spring.cloud.consul.discovery.port=4452",
"spring.cloud.consul.discovery.hostname=myhost",
"spring.cloud.consul.discovery.ipAddress=10.0.0.1"}, randomPort = true)
"spring.cloud.consul.discovery.ipAddress=10.0.0.1",
"spring.cloud.consul.discovery.registerHealthCheck=false", }, randomPort = true)
public class ConsulLifecycleCustomizedPropsTests {
@Autowired
@@ -76,6 +80,10 @@ public class ConsulLifecycleCustomizedPropsTests {
assertThat("property hostname was wrong", "myhost", equalTo(this.properties.getHostname()));
assertThat("property ipAddress was wrong", "10.0.0.1", equalTo(this.properties.getIpAddress()));
assertThat("service address was wrong", "myhost", equalTo(service.getAddress()));
Response<List<Check>> checkResponse = consul.getHealthChecksForService("myTestService", QueryParams.DEFAULT);
List<Check> checks = checkResponse.getValue();
assertThat("checks was wrong size", checks, hasSize(0));
}
}