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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With