- Mastering Spring Cloud
- Piotr Minkowski
- 156字
- 2021-08-27 18:57:05
Changing the instance identificator
Instances registered on Eureka are grouped by name, but each of them must send a unique ID, on the basis of which, the server is able to recognize it. Maybe you have noticed that instanceId is displayed in the dashboard for every service's group in the Status column. Spring Cloud Eureka automatically generates that number and it is equal to the combination of the following fields:
${spring.cloud.client.hostname}:${spring.application.name}:${spring.application.instance_id:${server.port}}}.
This identificator may be easily overridden with the eureka.instance.instanceId property. For testing purposes, let's launch some instances of the client application with the following configuration settings and the -DSEQUENCE_NO=[n] VM argument, where [n] is a sequence number starting from 1. Here's a sample configuration of a client's application that dynamically sets the listen port and discovery instanceId based on the SEQUENCE_NO parameter:
server:
port: 808${SEQUENCE_NO}
eureka:
instance:
instanceId: ${spring.application.name}-${SEQUENCE_NO}
The results may be viewed in the Eureka dashboard: