What is instanceid in spring eureka?

codingsplash picture codingsplash · Sep 13, 2017 · Viewed 8.6k times · Source

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?

Answer

Indra Basak picture Indra Basak · Sep 13, 2017

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