Netflix Eureka and 2 instances of the application in the local environment

I start working with Netflix Eureka and use version 1.1.145 ( https://github.com/Netflix/eureka/tree/1.1.145 ).

I want to run locally 2 instances of the same application on different ports, and they are both registered with Eureka. I am using an example service ( https://github.com/Netflix/eureka/blob/1.1.145/eureka-server/conf/sampleservice/sample-eureka-service.properties )

So, I start Eureka myself and 2 instances using the above configuration - one application on port 8001 and the other on 8002.

For some reason, I only get one instance registered with Eureka at any given time. Both of them start without exception and can talk with Eureka OK. When I start the second instance, it simply overwrites the information about the first instance with its own information.

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

What am I missing?

+1
spring-cloud netflix-eureka netflix
source share
3 answers

The default instance ID is the host name, so to run two of them on the same host, you need to manually set eureka.instance.metadataMap.instanceId (which works in the Spring Cloud application).

+5
source share

I am using spring-boot-starter-parent 1.5.1.RELEASE, but

 eureka.instance.metadataMap.instanceId 

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

first set server.port to zero:

 server: port: 0 # HTTP (Tomcat) port 

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

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

if you prefer a long random case, you can use random.value as follows:

 eureka: instance: instanceId: ${spring.application.name}:${random.value} 
+1
source share

If you need multiple service instances on the same host, you explicitly specify their instanceId when they start as follows:

  mvn spring-boot:run -Dserver.port=8081 -Deureka.instance.metadataMap.instanceId=instance1 mvn spring-boot:run -Dserver.port=8082 -Deureka.instance.metadataMap.instanceId=instance2 ... 

Or

  java -jar target/app.jar -Dserver.port=8081 -Deureka.instance.metadataMap.instanceId=instance1 ... 

You can also do this dynamically by specifying this in the application properties file:

 eureka.instance.instanceId: applicationname:${spring.application.instance_id:${random.value}} 

And I'm not sure that this is connected, but the refusal to register with the eureka took a very long time when I closed the instances (they can never cancel the registration), so I had to switch the self-preservation mode:

eureka.server.enable-self-preservation to false

0
source share

All Articles