UPDATE
The README in this repo has been updated to demonstrate the solution in the accepted answer.
I am working with a simple example of registering and opening Boot Eureka boot service based on this guide .
If I run one instance of the client, it registers correctly, and it can see itself through DiscoveryClient . If I run the second instance with a different name, it also works.
But if I run two instances with the same name, only one instance is displayed on the dashboard, and DiscoveryClient shows only the second instance.
When I kill the second instance, the first one is displayed again through the control panel and the discovery client.
Here are a few details about the steps I take and what I see:
Eureka Server
Start the server
cd eureka-server mvn spring-boot:run
Visit the Eureka dashboard at http: // localhost: 8761
Please note that there are no βinstancesβ registered yet.
Eureka Client
Start the client
cd eureka-client mvn spring-boot:run
Visit the client directly at http: // localhost: 8080 /
The endpoint /whoami will show the client self-identification of the name of its application and port
{ "springApplicationName":"eureka-client", "serverPort":"8080" }
The /instances endpoint will take up to a minute to update, but should ultimately show all eureka-client instances that have been registered with the Eureka Discovery Client.
[ { "host":"hostname", "port":8080, "serviceId":"EUREKA-CLIENT", "uri":"http://hostname:8080", "secure":false } ]
Now you can visit Eureka dashoboard again and see it there.
Move another client with a different name
You can see that another client will be registered by following these steps:
cd eureka-client mvn spring-boot:run -Dspring.application.name=foo -Dserver.port=8081
The endpoint /whoami will display the name foo and port 8081 .
After a minute or so, the endpoint /instances will display information about this foo instance.
Two clients will now be registered on the Eureka dashboard.
Hide another client with the same name
Now try turning on another instance of eureka-client just by moving the port parameter:
cd eureka-client mvn spring-boot:run -Dserver.port=8082
The /whoami endpoint for http://localhost:8082 shows what we expect.
After a minute or so, the /instances endpoint now also shows an instance running on port 8082, but for some reason it does not show an instance running on port 8080.
And if we check the endpoint /instances at http://localhost:8080 , now we will see only the instance running on 8082 (although, obviously, the one that runs on 8080 since we ask.
The Eureka toolbar shows only 1 instance of eureka-client .
What's going on here?
Try to kill the instance running on 8082 and see what happens.
When we request /instances at 8080, it still shows only an instance at 8082.
But in a minute it will disappear, and we will again see an instance at 8080.
The question is, why do not we see both eureka-client instances when they both work?