[spring-cloud-sleuth/#83] Fixed the way localinstance's id is returned. Fixes spring-cloud-sleuth/#83

This commit is contained in:
Marcin Grzejszczak
2015-12-31 12:46:51 +01:00
parent e1bd05394f
commit de25a0973d
4 changed files with 10 additions and 2 deletions

View File

@@ -52,7 +52,7 @@ public class ZookeeperDiscoveryClient implements DiscoveryClient {
@Override
public org.springframework.cloud.client.ServiceInstance getLocalServiceInstance() {
ServiceInstance<ZookeeperInstance> serviceInstance = this.serviceDiscovery.getServiceInstance();
return serviceInstance == null ? null : createServiceInstance(serviceInstance.getId(), serviceInstance);
return serviceInstance == null ? null : createServiceInstance(serviceInstance.getName(), serviceInstance);
}
private static org.springframework.cloud.client.ServiceInstance createServiceInstance(String serviceId, ServiceInstance<ZookeeperInstance> serviceInstance) {

View File

@@ -26,6 +26,7 @@ import lombok.Data;
@AllArgsConstructor
public class ZookeeperInstance {
private String id;
private String name;
@SuppressWarnings("unused")
private ZookeeperInstance() {

View File

@@ -113,7 +113,7 @@ public class ZookeeperServiceDiscovery implements ApplicationContextAware {
// @formatter:off
serviceInstance.set(ServiceInstance.<ZookeeperInstance>builder()
.name(appName)
.payload(new ZookeeperInstance(context.getId()))
.payload(new ZookeeperInstance(context.getId(), appName))
.port(port.get())
.address(host)
.uriSpec(uriSpec).build());

View File

@@ -68,6 +68,13 @@ class ZookeeperDiscoveryISpec extends Specification implements PollingUtils {
'UP' == registeredServiceStatus(instance)
}
def 'should present application name as id of the service instance'() {
given:
ServiceInstance instance = discoveryClient.getLocalServiceInstance()
expect:
springAppName == instance.serviceId
}
def 'should find an instance using feign via service id'() {
expect:
conditions.eventually willPass {