Search code examples
spring-bootspring-cloudnetflix-eureka

What is the difference between eureka.instance.instance-id and eureka.instance.metadataMap.instanceId?


What is the difference between eureka.instance.instance-id and eureka.instance.metadataMap.instanceId? I ran 2 instances of same service on same host (localhost) and to have a unique instanceId, I tried both eureka.instance.instance-id and eureka.instance.metadataMap.instanceId. Both properties worked fine and service instances registered successfully with eureka server.

I found below post where both the option are given

how to create multiple instances of eureka services registered into eureka service registry?

So, what is the difference between them and where should I use these properties?


Solution

  • There isn't any as such. We can use both :).

    When eureka server asks for instanceId while registering client here is what it gets-

    @Override
    public String getInstanceId() {
        if (this.instanceId == null && this.metadataMap != null) {
            return this.metadataMap.get("instanceId");
        }
        return this.instanceId;
    }
    

    So, if you set it using eureka.instance.instance-id it returns the same otherwise it tries to find the instanceId from metadata (which is set using- eureka.instance.metadataMap.instanceId).

    You can check EurekaInstanceConfigBean class for more details.