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

snehal picture snehal · Mar 2, 2017 · Viewed 10.7k times · Source

I have created eureka service registry and registered services into that. Currently only one instance of a service is running. How to add multiple instances of a same service? I am developing standalone application. And I am accessing services through Rest Template.I am following https://spring.io/guides/gs/service-registration-and-discovery/

Answer

ootero picture ootero · Mar 6, 2017

Each instance would need to have a unique instanceId, normally configured in application.yml using:

...
eureka:
   instance:
     metadataMap:
       instanceId: ${spring.application.name}:${server.port}
...

Adding the port to the instanceId allows to run multiple instances in the same host.

I have also seen adding a random number instead of the port the instance listens on.

I blogged about service registration and discovery using Jersey, Spring, Eureka, Ribbon and Feign with accompanying source code at http://tech.asimio.net/2016/11/14/Microservices-Registration-and-Discovery-using-Spring-Cloud-Eureka-Ribbon-and-Feign.html

And more recently blogged about how to register and discover multiple versions of a service using Eureka and Ribbon at http://tech.asimio.net/2017/03/06/Multi-version-Service-Discovery-using-Spring-Cloud-Netflix-Eureka-and-Ribbon.html.