From f930208c2e8763c30c69d64ec1053b0e6b07e028 Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Wed, 17 Jan 2018 15:50:30 -0500 Subject: [PATCH] Add option to not include hostname in default id. --- .../org/springframework/cloud/commons/util/IdUtils.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/commons/util/IdUtils.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/commons/util/IdUtils.java index e9e70645..dd8751ee 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/commons/util/IdUtils.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/commons/util/IdUtils.java @@ -11,12 +11,19 @@ public class IdUtils { private static final String SEPARATOR = ":"; public static String getDefaultInstanceId(PropertyResolver resolver) { + return getDefaultInstanceId(resolver, true); + } + + public static String getDefaultInstanceId(PropertyResolver resolver, boolean includeHostname) { String vcapInstanceId = resolver.getProperty("vcap.application.instance_id"); if (StringUtils.hasText(vcapInstanceId)) { return vcapInstanceId; } - String hostname = resolver.getProperty("spring.cloud.client.hostname"); + String hostname = null; + if (includeHostname) { + hostname = resolver.getProperty("spring.cloud.client.hostname"); + } String appName = resolver.getProperty("spring.application.name"); String namePart = combineParts(hostname, SEPARATOR, appName);