To connect client apps to the Service Registry, Spring Cloud Services uses Spring Cloud Connectors, including the Spring Cloud Cloud Foundry Connector, which discovers services bound to apps running in Cloud Foundry.

Application Configuration

In a Spring Boot app which is bound to a Service Registry service instance, the connector automatically configures a Spring Cloud Netflix Eureka client configuration bean. The client configuration includes the discovery zone, which is configured using the URL from the service binding; this is equivalent to setting the eureka.client.serviceUrl.defaultZone property.

Eureka Application Name Configuration

A client app registers with the Spring Cloud Services Service Registry using an application name. This value is used by Netflix Eureka to look up instances of an app and to set Eureka's virtual hostname and secure virtual hostname for the app. In an app that registers with a Spring Cloud Netflix Eureka server, the Eureka application name is by default the value of the app's property. If the value of the app's property is used for the Eureka application name and contains one or more characters which are invalid in a hostname, the Spring Cloud Services connector for Service Registry sanitizes that value by using a hyphen (-) to replace each invalid character.

You can register a client app with the Service Registry using an application name that differs from To do so, you must set the eureka.instance.appname property. If set, this value will be used verbatim for the app's Eureka application name, virtual hostname, and secure virtual hostname; it therefore must contain only characters which are valid in a hostname.

Examples of values provided for the eureka.instance.appname property, values provided for the property, and the Eureka application names resulting from combinations of these values or from providing a given value for but none for eureka.instance.appname are listed below.

eureka.instance.appname Resultant application name
vhn san vhn
v_hn san v_hn
(not provided) san san
(not provided) s_an s-an
x_y x_y x_y

Application Name Property Restrictions

To identify instances of an app, Netflix Eureka uses three eureka.instance properties: appname, virtualHostName, and secureVirtualHostName. For consistency with Spring Cloud features such as Spring Cloud Netflix Zuul's automatic routing to registered apps and the load-balanced RestTemplate using Spring Cloud Netflix Ribbon, and to secure ownership of Eureka application names, the Spring Cloud Services Service Registry rejects a registration that includes different non-null values for any of these three properties.

If you set only the property or the eureka.instance.appname property, the Spring Cloud Services connector will set the eureka.instance.virtualHostName and eureka.instance.secureVirtualHostname properties to the same value. If you explicitly set different values for eureka.instance.appname, eureka.instance.virtualHostName, and eureka.instance.secureVirtualHostName, the Spring Cloud Services connector will prevent the app from starting, and you will see an error message in the application logs:

eureka.instance.virtualHostName 'foo' is set to a different value than
eureka.instance.appname 'bar', and is disallowed in Spring Cloud Services.
Try only setting eureka.instance.appname. Please refer to our documentation
and reach out to us if you think you require different values.

Instance-Specific Routing in Ribbon

The Spring Cloud Services Connectors include the Cloud Foundry application GUID and instance ID in Ribbon request headers when these values are available. This allows Ribbon to specify a particular instance of an application when making a request. The Gorouter respects such instance-specific routing decisions as made by Ribbon.

Instance-specific routing is performed by Ribbon in the Spring Cloud Services Connectors automatically. For example, if an app has three instances A, B, and C, and A has a Eureka status other than UP, Ribbon specifies another instance--either B or C--when making a request to that app, and the Gorouter respects this specific choice by Ribbon even if the Gorouter considers A healthy. The application GUID and instance ID metadata included in Ribbon requests can also be used to write custom routing logic in Ribbon clients within apps using the Spring Cloud Services Services Connectors.

See Also

For more information about Spring Cloud Connectors, see the following:

check-circle-line exclamation-circle-line close-line
Scroll to top icon