How to config multiple Eureka Servers from client in Spring Cloud

谁说胖子不能爱 提交于 2019-11-27 00:53:12

问题


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:


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

eureka.client.serviceUrl.defaultZone=http://<peer1host>:<peer1port>/eureka,http://<peer2host>:<peer2port>/eureka


来源:https://stackoverflow.com/questions/30850232/how-to-config-multiple-eureka-servers-from-client-in-spring-cloud

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!