sne*_*hal 5 spring-cloud-netflix
我已经创建了eureka服务注册表,并在其中注册了服务。当前,仅服务的一个实例正在运行。如何添加同一服务的多个实例?我正在开发独立应用程序。我正在通过Rest Template访问服务。我正在关注https://spring.io/guides/gs/service-registration-and-discovery/
每个实例都需要具有唯一的instanceId,通常application.yml使用以下命令进行配置:
...
eureka:
instance:
metadataMap:
instanceId: ${spring.application.name}:${server.port}
...
Run Code Online (Sandbox Code Playgroud)
将端口添加到instanceId允许在同一主机上运行多个实例。
我还看到添加了一个随机数,而不是实例侦听的端口。
我在博客服务的注册和发现使用Jersey,Spring,Eureka,Ribbon和Feign与在伴随的源代码http://tech.asimio.net/2016/11/14/Microservices-Registration-and-Discovery-using-Spring-Cloud-Eureka-Ribbon -and-Feign.html
最近有一篇关于如何使用Eureka和注册和发现服务的多个版本的博客,网址Ribbon为http://tech.asimio.net/2017/03/06/Multi-version-Service-Discovery-using-Spring-Cloud-Netflix- Eureka-and-Ribbon.html。
如果要在同一主机上运行一项服务的多个实例,则必须:
这两个必须单独配置,例如
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)
一旦你有了这个关于 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 自我保存和更新阈值。希望这可以帮助。
| 归档时间: |
|
| 查看次数: |
6696 次 |
| 最近记录: |