Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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/

like image 295
snehal Avatar asked Mar 02 '17 11:03

snehal


People also ask

How do I register two instances with Eureka server?

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.

How do I create multiple instances of microservices?

Multiple Service Instances per Host Pattern. One way to deploy your microservices is to use the Multiple Service Instances per Host pattern. When using this pattern, you provision one or more physical or virtual hosts and run multiple service instances on each one.

How do I register multiple microservices in Eureka server?

First, you need to add the following dependencies in our build configuration file to register the microservice with the Eureka server. Now, we need to add the @EnableEurekaClient annotation in the main Spring Boot application class file.

Can we have multiple Eureka servers?

Because you can have multiple instances of Eureka Servers and they can register with each other so that if one Server fails another server can still provide service.


2 Answers

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.

like image 88
ootero Avatar answered Oct 10 '22 21:10

ootero


If you aim to run multiple instances of one service on a same host, you must:

  1. configure Eureka instance-id with a random number
  2. configure the service use a random port number

These two must be configured individually, e.g.

eureka:
  instance:
    instance-id: ${spring.cloud.client.hostname}:${spring.application.name}:${spring.application.instance_id:${random.value}}

and

server:
  port: 0
like image 28
BurnetZhong Avatar answered Oct 10 '22 21:10

BurnetZhong