如何创建在eureka服务注册表中注册的多个eureka服务实例?

sne*_*hal 5 spring-cloud-netflix

我已经创建了eureka服务注册表,并在其中注册了服务。当前,仅服务的一个实例正在运行。如何添加同一服务的多个实例?我正在开发独立应用程序。我正在通过Rest Template访问服务。我正在关注https://spring.io/guides/gs/service-registration-and-discovery/

oot*_*ero 7

每个实例都需要具有唯一的instanceId,通常application.yml使用以下命令进行配置:

...
eureka:
   instance:
     metadataMap:
       instanceId: ${spring.application.name}:${server.port}
...
Run Code Online (Sandbox Code Playgroud)

将端口添加到instanceId允许在同一主机上运行多个实例。

我还看到添加了一个随机数,而不是实例侦听的端口。

我在博客服务的注册和发现使用JerseySpringEurekaRibbonFeign与在伴随的源代码http://tech.asimio.net/2016/11/14/Microservices-Registration-and-Discovery-using-Spring-Cloud-Eureka-Ribbon -and-Feign.html

最近有一篇关于如何使用Eureka和注册和发现服务的多个版本的博客,网址Ribbonhttp://tech.asimio.net/2017/03/06/Multi-version-Service-Discovery-using-Spring-Cloud-Netflix- Eureka-and-Ribbon.html


Bur*_*ong 6

如果要在同一主机上运行一项服务的多个实例,则必须:

  1. 使用随机数配置Eureka实例ID
  2. 使用随机端口号配置服务

这两个必须单独配置,例如

eureka:
  instance:
    instance-id: ${spring.cloud.client.hostname}:${spring.application.name}:${spring.application.instance_id:${random.value}}
Run Code Online (Sandbox Code Playgroud)

server:
  port: 0
Run Code Online (Sandbox Code Playgroud)


Gri*_*pal 2

一旦你有了这个关于 eureka 对等感知的官方 spring-cloud文档,你肯定会需要另一个 eureka 实例。

简而言之,您需要做的就是通过在各自的 application.yml 中添加彼此的信息来让他们彼此了解。希望这可以帮助。阅读文档以了解详细信息。

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

---
spring:
  profiles: peer2
eureka:
  instance:
    hostname: peer2
  client:
    serviceUrl:
      defaultZone: http://peer1/eureka/
Run Code Online (Sandbox Code Playgroud)

其他几个链接可以了解 Eureka github 问题了解 Spring Cloud Eureka Server 自我保存和更新阈值。希望这可以帮助。