add support for scheme, currently used in http health check

fixes gh-33
This commit is contained in:
Spencer Gibb
2015-06-04 09:16:04 -06:00
parent c1121ffc3d
commit 76b0c2f7f2
3 changed files with 9 additions and 3 deletions

View File

@@ -66,6 +66,8 @@ public class ConsulDiscoveryProperties {
private String instanceId;
private String scheme = "http";
public String getHostname() {
return this.preferIpAddress ? this.ipAddress : this.hostname;
}

View File

@@ -23,6 +23,7 @@ import org.springframework.cloud.client.discovery.AbstractDiscoveryLifecycle;
import com.ecwid.consul.v1.ConsulClient;
import com.ecwid.consul.v1.agent.model.NewService;
import org.springframework.util.Assert;
/**
* @author Spencer Gibb
@@ -56,6 +57,7 @@ public class ConsulLifecycle extends AbstractDiscoveryLifecycle {
@Override
protected void register() {
Assert.notNull(service.getPort(), "service.port has not been set");
String appName = getAppName();
String id;
if (properties.getInstanceId() == null) {
@@ -74,8 +76,9 @@ public class ConsulLifecycle extends AbstractDiscoveryLifecycle {
if (properties.getHealthCheckUrl() != null) {
check.setHttp(properties.getHealthCheckUrl());
} else {
check.setHttp(String.format("http://%s:%s%s", properties.getHostname(),
service.getPort(), properties.getHealthCheckPath()));
check.setHttp(String.format("%s://%s:%s%s", properties.getScheme(),
properties.getHostname(), service.getPort(),
properties.getHealthCheckPath()));
}
check.setInterval(properties.getHealthCheckInterval());
//TODO support http check timeout

View File

@@ -46,7 +46,8 @@ import com.ecwid.consul.v1.agent.model.Service;
@RunWith(SpringJUnit4ClassRunner.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@SpringApplicationConfiguration(classes = TestPropsConfig.class)
@WebIntegrationTest(value = {"spring.application.name=myTestService", "spring.cloud.consul.discovery.instanceId=myTestService1"}, randomPort = true)
@WebIntegrationTest(value = { "spring.application.name=myTestService",
"spring.cloud.consul.discovery.instanceId=myTestService1" }, randomPort = true)
public class ConsulLifecycleCustomizedPropsTests {
@Autowired