2017-03-02 100 views

回答

2

您一定會需要另一個尤里卡實例,一旦您有這個官方春雲documentation尤里卡同儕意識。

簡而言之,您需要做的就是通過在各自的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/ 

夫婦等各個環節的瞭解尤里卡github IssueUnderstanding Spring Cloud Eureka Server self preservation and renew threshold。希望這可以幫助。

0

每個實例都需要有一個獨特的instanceId,通常在application.yml配置使用:

... 
eureka: 
    instance: 
    metadataMap: 
     instanceId: ${spring.application.name}:${server.port} 
... 

端口加入的instanceId允許在同一臺主機上運行多個實例。

我也看到添加一個隨機數而不是實例監聽的端口。

我的博客上講述服務註冊和發現在http://tech.asimio.net/2016/11/14/Microservices-Registration-and-Discovery-using-Spring-Cloud-Eureka-Ribbon-and-Feign.html

而最近使用JerseySpringEurekaRibbonFeign伴隨源代碼的博客上講述使用EurekaRibbon如何註冊和發現服務的多個版本在http://tech.asimio.net/2017/03/06/Multi-version-Service-Discovery-using-Spring-Cloud-Netflix-Eureka-and-Ribbon.html

+0

酷,好文章,所以用佯的時候,想有像的「人口統計學2實例的服務不止一個實例註冊-api-1「,當我在假客戶端使用@FeignClient(」demo-registration-api-1「)'註釋時,這兩個實例服務是否被消耗? –

+0

@LipingHuang這是正確的 – ootero

+0

謝謝,所以這是否有一個平衡?否則這些是重複的呼叫。 –

0

如果你的目標是在同一臺主機上運行一個服務的多個實例,你必須:

  1. 配置尤里卡實例ID與隨機數
  2. 配置該服務使用一個隨機端口號

這兩個必須單獨配置,例如

eureka: 
    instance: 
    instance-id: ${spring.cloud.client.hostname}:${spring.application.name}:${spring.application.instance_id:${random.value}} 

server: 
    port: 0 
相關問題