Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is instanceid in spring eureka?

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?

like image 927
codingsplash Avatar asked Sep 13 '17 11:09

codingsplash


2 Answers

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

like image 173
Indra Basak Avatar answered Oct 10 '22 01:10

Indra Basak


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.

like image 7
Darren Forsythe Avatar answered Oct 10 '22 01:10

Darren Forsythe