Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Netflix Eureka and 2 instances of application on local environment

I'm getting started with Netflix Eureka and using its 1.1.145 (https://github.com/Netflix/eureka/tree/1.1.145) version.

I want to start locally 2 instances of the same application on different ports and have them both registered with Eureka. I'm using sample service (https://github.com/Netflix/eureka/blob/1.1.145/eureka-server/conf/sampleservice/sample-eureka-service.properties)

So I start Eureka itself and 2 instances using above config - one app on 8001 port and another on 8002.

For some reason I'm getting only one instance registered with Eureka at any given time. Both of them start without exceptions and can talk to Eureka OK. When I start a second instance, it seems to simply overwrite info about 1st instance with its own info.

What I want is to have 2 'instance' elements under the same logical eureka.name at http://localhost/eureka/v2/apps

What am I missing?

like image 283
Alex Avatar asked Sep 02 '25 02:09

Alex


2 Answers

The default instance ID is the host name, so to run two of anything on the same host you need to manually set the eureka.instance.metadataMap.instanceId (that works in a Spring Cloud app anyway).

like image 184
Dave Syer Avatar answered Sep 06 '25 18:09

Dave Syer


I'm using spring-boot-starter-parent 1.5.1.RELEASE but

eureka.instance.metadataMap.instanceId 

does not work, so I found a solution for my app

first, set server.port to zero:

server:
  port: 0   # HTTP (Tomcat) port

then set eureka.instance.instanceId, to something random. I used integer randoms:

eureka:
  instance:
    instanceId: ${spring.application.name}:${random.int}

if you prefer a long random, you can use random.value like this:

eureka:
  instance:
    instanceId: ${spring.application.name}:${random.value}
like image 37
byOnti Avatar answered Sep 06 '25 19:09

byOnti