diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/DefaultServiceInstance.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/DefaultServiceInstance.java index b9038ac8b..475640b3d 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/DefaultServiceInstance.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/DefaultServiceInstance.java @@ -17,6 +17,7 @@ package org.springframework.cloud.client; import java.net.URI; +import java.util.Map; import lombok.Data; @@ -36,11 +37,18 @@ public class DefaultServiceInstance implements ServiceInstance { private final boolean secure; + private final Map metadata; + @Override public URI getUri() { return getUri(this); } + @Override + public Map getMetadata() { + return null; + } + /** * Create a uri from the given ServiceInstance's host:port * @param instance diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/ServiceInstance.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/ServiceInstance.java index 7cd52f72f..ca99e6923 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/ServiceInstance.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/ServiceInstance.java @@ -17,6 +17,7 @@ package org.springframework.cloud.client; import java.net.URI; +import java.util.Map; /** * Represents an instance of a Service in a Discovery System @@ -27,23 +28,30 @@ public interface ServiceInstance { /** * @return the service id as register by the DiscoveryClient */ - public String getServiceId(); + String getServiceId(); /** * @return the hostname of the registered ServiceInstance */ - public String getHost(); + String getHost(); /** * @return the port of the registered ServiceInstance */ - public int getPort(); + int getPort(); /** - * @return ifthe port of the registered ServiceInstance is https or not + * @return if the port of the registered ServiceInstance is https or not */ - public boolean isSecure(); + boolean isSecure(); - public URI getUri(); + /** + * @return the service uri address + */ + URI getUri(); + /** + * @return the key value pair metadata associated with the service instance + */ + Map getMetadata(); } diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/noop/NoopDiscoveryClientAutoConfiguration.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/noop/NoopDiscoveryClientAutoConfiguration.java index c7dac7257..5d8f9f96a 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/noop/NoopDiscoveryClientAutoConfiguration.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/noop/NoopDiscoveryClientAutoConfiguration.java @@ -18,6 +18,7 @@ import java.net.InetAddress; import java.net.UnknownHostException; +import java.util.Collections; import javax.annotation.PostConstruct; @@ -72,7 +73,7 @@ public void init() { } int port = findPort(); this.serviceInstance = new DefaultServiceInstance(this.environment.getProperty( - "spring.application.name", "application"), host, port, false); + "spring.application.name", "application"), host, port, false, Collections.emptyMap()); } private int findPort() { diff --git a/spring-cloud-commons/src/test/java/org/springframework/cloud/client/loadbalancer/LoadBalancerAutoConfigurationTests.java b/spring-cloud-commons/src/test/java/org/springframework/cloud/client/loadbalancer/LoadBalancerAutoConfigurationTests.java index f672d9bc5..c1b0a8ed7 100644 --- a/spring-cloud-commons/src/test/java/org/springframework/cloud/client/loadbalancer/LoadBalancerAutoConfigurationTests.java +++ b/spring-cloud-commons/src/test/java/org/springframework/cloud/client/loadbalancer/LoadBalancerAutoConfigurationTests.java @@ -8,10 +8,7 @@ import static org.junit.Assert.assertThat; import java.net.URI; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Random; +import java.util.*; import lombok.SneakyThrows; @@ -116,7 +113,8 @@ private static class NoopLoadBalancerClient implements LoadBalancerClient { @Override public ServiceInstance choose(String serviceId) { - return new DefaultServiceInstance(serviceId, serviceId, random.nextInt(40000), false); + return new DefaultServiceInstance(serviceId, serviceId, random.nextInt(40000), + false, Collections.emptyMap()); } @Override