Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to config multiple Eureka Servers from client in Spring Cloud

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

like image 883
user3006967 Avatar asked Jun 15 '15 16:06

user3006967


People also ask

Can we have multiple Eureka servers?

Generally, there will be multiple Eureka servers running so that to make it highly available. This is actually running multiple instances that intercommunicate with each other and what they do is they copy the replicate state of the registered services between them.

Which mode of Eureka server has multiple Eureka servers?

defaultZone property. The Eureka server works in two modes: Standalone: in local, we configure a stand-alone mode where we have only one Eureka server (localhost) and the same cloning property from itself. Clustered: we have multiple Eureka servers, each cloning its states from its peer.

What is Eureka client serviceUrl defaultZone?

eureka: client: serviceUrl: defaultZone: http://localhost:8761/eureka/ In the preceding example, "defaultZone" is a magic string fallback value that provides the service URL for any client that does not express a preference (in other words, it is a useful default).


1 Answers

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

eureka.client.serviceUrl.defaultZone=http://<peer1host>:<peer1port>/eureka,http://<peer2host>:<peer2port>/eureka
like image 191
spencergibb Avatar answered Oct 08 '22 17:10

spencergibb