11

I read that instance id of Eureka Clients have to be unique and when we wish to run multiple instances of the same Eureka Client, then we add this property:

eureka.instance.instance-id==${spring.cloud.client.hostname}:${spring.application.name}:${spring.application.instance_id:${random.value}}

What is the significance of instance Id and how does the above line matter?

Cœur
  • 37,241
  • 25
  • 195
  • 267
codingsplash
  • 4,785
  • 12
  • 51
  • 90

2 Answers2

15

A Eureka Client has an app ID and an instance ID. The app ID is the name of the application while the instance ID is the unique id associated with the instance of the client.

This helps Eureka Server to make a distinction between different client instances of the same application. In your example, the line shown below sets up a unique instance ID for your application having format: <client host name>:<client app name>:<some random number>

eureka.instance.instance-id==${spring.cloud.client.hostname}:${spring.application.name}:${spring.application.instance_id:${random.value}}

In my example shown below, the instance ID has the format - <host name>:<app id>:<port>. The Eureka REST operation shown below will change the status of eureka client with app ID of AUTHOR and instance ID of 10.16.6.76:author:8766 to OUT_OF_SERVICE.

localhost:8761/eureka/apps/AUTHOR/10.16.6.76:author:8766/status?value=OUT_OF_SERVICE 

If you noticed, Eureka Server can uniquely identify a client if you provide both the application ID and the instance ID.

enter image description here

Indra Basak
  • 7,124
  • 1
  • 26
  • 45
7

It is used to uniquely ID a single instance of multiple services E.g. if you deployed 2x instances of the same spring boot application the instance ID is used to distinguish between them.

Some additional use cases for PCF and AWS w/ Instance ID can be found in the documentation.

https://cloud.spring.io/spring-cloud-netflix/multi/multi__service_discovery_eureka_clients.html

The above property simply takes the other properties, combines them. The only gotcha above is that if a spring.application_instance_id is not found in the environment it will use a random.value instead. You can override however you like but it should be unique.

Darren Forsythe
  • 10,712
  • 4
  • 43
  • 54
  • 1
    I read that the default instance id is host:port. So if my instances are running on different ports, and hence have unique instance id's, then why do I need to edit the instance id like this? – codingsplash Sep 22 '17 at 11:13
  • you don't need to if you can guarantee that your applications will be running on different ports and the instance ID *will* be unique. When deploying onto something like PCF it will not be unique as the port will be set for each instance thus the instance IDs will clash. – Darren Forsythe Sep 22 '17 at 12:40