34

From the spring doc, I see we can have peer eureka server together, so for Eureka1, in application.yml, I can have:

spring:
  profiles: peer1
eureka:
  instance:
    hostname: peer1
  client:
    serviceUrl:
      defaultZone: http://peer2/eureka/

And in Eureka Server 2, I can have:

spring:
  profiles: peer2
eureka:
  instance:
    hostname: peer2
  client:
    serviceUrl:
      defaultZone: http://peer1/eureka/

Now these two eureka servers are aware each other, it is good. BUT, now in configuring client, when they register again Eureka, how to do this?

In my client application, I have:

eureka:
      instance:
        hostname: ${host.instance.name:localhost}
        nonSecurePort: ${host.instance.port:8080}
        leaseRenewalIntervalInSeconds: 5 #default is 30, recommended to keep default
        metadataMap:
          instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}
      client:
        serviceUrl:
          defaultZone: http://(eurekaServerHost):8761/eureka/

    server:
      port: ${host.instance.port:8080}

So now my question is shall I use peer1 or peer2 as EurekaServerHost in the client application.yml?

Thanks

user3006967
  • 2,551
  • 9
  • 36
  • 58

1 Answers1

38

Use a comma separated list of peers in eureka.client.serviceUrl.defaultZone.

eureka.client.serviceUrl.defaultZone=http://<peer1host>:<peer1port>/eureka,http://<peer2host>:<peer2port>/eureka
spencergibb
  • 20,382
  • 5
  • 55
  • 64
  • 1
    This is not working for my case. I am putting couple of Eureka hosts as comma seperated list in eureka client application. However it is only registering with the first one in the list. Please help. – Khuzi Mar 23 '16 at 04:44
  • 6
    from https://github.com/Netflix/eureka/wiki/Understanding-Eureka-Peer-to-Peer-Communication "Once the server starts receiving traffic, all of the operations that is performed on the server is replicated to all of the peer nodes that the server knows about. If an operation fails for some reason, the information is reconciled on the next heartbeat that also gets replicated between servers." – pshirishreddy Aug 26 '16 at 08:33
  • @spencergibb - Could you please guide me here: https://stackoverflow.com/questions/53955173/eureka-replication-not-showing-the-dashboard ? – Jeff Cook Dec 28 '18 at 07:41
  • @spencergibb: Can we give the URL for a load-balancer setup in front of eureka instances? In this way I don't have to modify my service URL every time a new Eureka instance is added. Though I tried, but replication is not working. You can refer to my setup [here](https://stackoverflow.com/questions/59489749/microservices-not-registering-on-all-eureka-instances) – Priyam Dec 27 '19 at 03:15
  • I wouldn't recommend using eureka behind a load-balancer. – spencergibb Jan 03 '20 at 18:29
  • @spencergibb Can you please let me know any specific reason for it? – Priyam Jan 31 '20 at 03:24
  • Eureka was built in a way that every client needs to know about every peer – spencergibb Feb 01 '20 at 04:37