Register multiple Instances of a Spring Boot Eureka Client from a single host

痞子三分冷 提交于 2019-12-04 04:16:25

For local deployments, try to configure {namespace}.instanceId property in eureka-client.properties (or eureka.instance.metadataMap.instanceId for proper yaml file in case of Spring Cloud based setup). It's deeply rooted in the way Eureka server calculates application lists and compares InstanceInfo for the PeerAwareInstanceRegistryImpl - when no more concrete data (e.g.: instance metadata is available) they try to get the id from the hostname..

I wouldn't recommend it for AWS deployment though, cause messing around with instanceId will bring you trouble figuring out which machine hosts a particular service - on the other hand I doubt that you'll hosts two identical services on one machine, right?

In order to get all instances show up in the admin portal by setting unique euraka.instance.hostname in your Eureka configuration file.

The hostname is used as key for storing the InstanceInfo in com.netflix.discovery.shared.Application (since no UniqueIdentifier is set). So you have to use unique hostnames. When you test ribbon in this scenario you would see that the load won't be balanced.

Following application.yml is example:

server:
  port: ${PORT:0}

info:
  component: example.server

logging:
  level:
    com.netflix.discovery: 'OFF'
    org.springframework.cloud: 'DEBUG'

eureka:
  instance:
    leaseRenewalIntervalInSeconds: 1
    leaseExpirationDurationInSeconds: 1
    metadataMap:
      instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}
    instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}

It's a bug before in Eureka, you can check further information in https://github.com/codecentric/spring-boot-admin/issues/134

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