36

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

1 Answer 1

41

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

eureka.client.serviceUrl.defaultZone=http://<peer1host>:<peer1port>/eureka,http://<peer2host>:<peer2port>/eureka
8
  • 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, 2016 at 4:44
  • 6
    from github.com/Netflix/eureka/wiki/… "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." Aug 26, 2016 at 8:33
  • @spencergibb - Could you please guide me here: stackoverflow.com/questions/53955173/… ?
    – Jeff Cook
    Dec 28, 2018 at 7: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
    – Priyam
    Dec 27, 2019 at 3:15
  • I wouldn't recommend using eureka behind a load-balancer. Jan 3, 2020 at 18:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.