Issue
I have set up two instances of my microservice on different ports, but only one instance is visible on the Eureka dashboard. I have set the following properties in my microservice's application.properties
file:
server.port=0
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
spring.application.name=Inventory-Service
However, when I check the Eureka dashboard, I can only see one instance of my microservice. I am sure that both instances are running. What could be the issue?
I am using Spring Boot and Spring Cloud. Any help would be appreciated. Thanks!
Solution
This is documented in this GitHub issue. The problem is that the default instance ID that is used to register with Eureka looks like this:
${spring.application.name}:${server.port}
So even if you run your microservice on a random port by using server.port=0
, the ID it uses within Eureka in both cases is Inventory-Service:0
. Since the ID has to be unique, only one instance is registered in Eureka.
The solution to this problem is to either not work with random ports, or to make sure you generate a unique Eureka ID for each instance.
For example:
eureka.instance.instance-id=${spring.application.name}:${random.int}
Answered By - g00glen00b
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.