Upgrade eureka to 1.2.5.

Change EurekaInstanceConfig.getSID to getInstanceId

fixes gh-554
This commit is contained in:
Spencer Gibb
2015-09-24 22:23:17 -06:00
parent da04c53726
commit 0204978b36
7 changed files with 18 additions and 19 deletions

View File

@@ -123,7 +123,7 @@ It's worth spending a bit of time understanding how the Eureka metadata works, s
==== Using Eureka on Cloudfoundry
Cloudfoundry has a global router so that all instances of the same app have the same hostname (it's the same in other PaaS solutions with a similar architecture). This isn't necessarily a barrier to using Eureka, but if you use the router (recommended, or even mandatory depending on the way your platform was set up), you need to explicitly set the hostname and port numbers (secure or non-secure) so that they use the router. You might also want to use instance metadata so you can distinguish between the instances on the client (e.g. in a custom load balancer). For example:
Cloudfoundry has a global router so that all instances of the same app have the same hostname (it's the same in other PaaS solutions with a similar architecture). This isn't necessarily a barrier to using Eureka, but if you use the router (recommended, or even mandatory depending on the way your platform was set up), you need to explicitly set the hostname and port numbers (secure or non-secure) so that they use the router. You might also want to use instance metadata so you can distinguish between the instances on the client (e.g. in a custom load balancer). By default, the `eureka.instance.instanceId` is `vcap.application.instance_id`. For example:
.application.yml
----
@@ -131,8 +131,6 @@ eureka:
instance:
hostname: ${vcap.application.uris[0]}
nonSecurePort: 80
metadataMap:
instanceId: ${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${server.port}}}
----
Depending on the way the security rules are set up in your Cloudfoundry instance, you might be able to register and use the IP address of the host VM for direct service-to-service calls. This feature is not (yet) available on Pivotal Web Services (https://run.pivotal.io[PWS]).
@@ -153,16 +151,17 @@ public EurekaInstanceConfigBean eurekaInstanceConfig() {
}
----
==== Making the Eureka Instance ID Unique
==== Changing the Eureka Instance ID
By default a eureka instance is registered with an ID that is equal to its host name (i.e. only one service per host). Using Spring Cloud you can override this by providing a unique identifier in `eureka.instance.metadataMap.instanceId`. For example:
A vanilla Netflix Eureka instance is registered with an ID that is equal to its host name (i.e. only one service per host). Spring Cloud Eureka provides a sensible default that looks like this: `${spring.cloud.client.hostname}:${spring.application.name}:${spring.application.instance_id:${server.port}}}`. For example `myhost:myappname:8080`.
Using Spring Cloud you can override this by providing a unique identifier in `eureka.instance.instanceId`. For example:
.application.yml
----
eureka:
instance:
metadataMap:
instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}
instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}
----
With this metadata, and multiple service instances deployed on

View File

@@ -26,7 +26,7 @@
<spring-cloud-stream.version>1.0.0.BUILD-SNAPSHOT</spring-cloud-stream.version>
<main.basedir>${basedir}</main.basedir>
<archaius.version>0.6.5</archaius.version>
<eureka.version>1.2.5-rc.1</eureka.version>
<eureka.version>1.2.5</eureka.version>
<feign.version>8.10.0</feign.version>
<hystrix.version>1.4.15</hystrix.version>
<ribbon.version>2.1.0</ribbon.version>

View File

@@ -85,7 +85,7 @@ public class EurekaClientAutoConfiguration {
public EurekaInstanceConfigBean eurekaInstanceConfigBean() {
EurekaInstanceConfigBean instance = new EurekaInstanceConfigBean();
instance.setNonSecurePort(this.nonSecurePort);
instance.setSid(getDefaultInstanceId(env));
instance.setInstanceId(getDefaultInstanceId(env));
return instance;
}

View File

@@ -73,7 +73,7 @@ public class EurekaInstanceConfigBean implements EurekaInstanceConfig {
@Value("${spring.application.name:unknown}")
private String virtualHostName;
private String sid;
private String instanceId;
private String secureVirtualHostName;
@@ -112,11 +112,11 @@ public class EurekaInstanceConfigBean implements EurekaInstanceConfig {
}
@Override
public String getSID() {
if (this.sid == null && this.metadataMap != null) {
public String getInstanceId() {
if (this.instanceId == null && this.metadataMap != null) {
return this.metadataMap.get("instanceId");
}
return sid;
return instanceId;
}
@Override

View File

@@ -42,7 +42,7 @@ public class InstanceInfoFactory {
builder.setNamespace(config.getNamespace())
.setAppName(config.getAppname())
.setSID(config.getSID())
.setInstanceId(config.getInstanceId())
.setAppGroupName(config.getAppGroupName())
.setDataCenterInfo(config.getDataCenterInfo())
.setIPAddr(config.getIpAddress())

View File

@@ -68,11 +68,11 @@ public class EurekaInstanceConfigBeanTests {
}
@Test
public void sid() {
addEnvironment(this.context, "eureka.instance.sid:special");
public void instanceId() {
addEnvironment(this.context, "eureka.instance.instanceId:special");
setupContext();
EurekaInstanceConfigBean instance = getInstanceConfig();
assertEquals("special", instance.getSID());
assertEquals("special", instance.getInstanceId());
}
@Test

View File

@@ -31,8 +31,8 @@ public class InstanceInfoFactoryTests {
}
@Test
public void instanceIdIsSidWhenSet() {
InstanceInfo instanceInfo = setupInstance("eureka.instance.sid:special");
public void instanceInfoIdIsInstanceIdWhenSet() {
InstanceInfo instanceInfo = setupInstance("eureka.instance.instanceId:special");
assertEquals("special", instanceInfo.getId());
}