系列目錄:spring
本文基於SpringCloud-Dalston.SR5緩存
Eureka做爲服務註冊中心對整個微服務架構起着最核心的整合做用,所以對Eureka仍是有很大的必要進行深刻研究。安全
Eureka 1.x版本是純基於servlet的應用。爲了與spring cloud結合使用,除了自己eureka代碼,還有個粘合模塊spring-cloud-netflix-eureka-server。在咱們啓動EurekaServer實例的時候,只用加入對於spring-cloud-starter-eureka-server的依賴便可。以後經過@EnableEurekaServer註解便可啓動一個Eureka服務器實例。服務器
其官方文檔中對本身的定義是:網絡
Spring Cloud Netflix provides Netflix OSS integrations for Spring Boot apps through autoconfiguration and binding to the Spring Environment and other Spring programming model idioms. With a few simple annotations you can quickly enable and configure the common patterns inside your application and build large distributed systems with battle-tested Netflix components. The patterns provided include Service Discovery (Eureka), Circuit Breaker (Hystrix), Intelligent Routing (Zuul) and Client Side Load Balancing (Ribbon)..架構
Spring Cloud Netflix這個項目對於Spring Boot應用來講,它集成了NetFlix OSS的一些組件,只需經過註解配置和Spring環境的通用簡單的使用註解,你能夠快速的啓用和配置這些久經測試考驗的NetFlix的組件於你的應用和用於構建分佈式系統中。這些組件包含的功能有服務發現(Eureka),熔斷器(Hystrix),智能路由(Zuul)以及客戶端的負載均衡器(Ribbon) 簡單的來講,Spring Cloud NetFlix這個項目對NetFlix中一些久經考驗靠譜的服務發現,熔斷,網關,智能路由,以及負載均衡等作了封裝,並經過註解的或簡單配置的方式提供給Spring Cloud用戶用。app
Eureka is a REST (Representational State Transfer) based service that is primarily used in the AWS cloud for locating services for the purpose of load balancing and failover of middle-tier servers. We call this service, the Eureka Server. Eureka also comes with a Java-based client component,the Eureka Client, which makes interactions with the service much easier. The client also has a built-in load balancer that does basic round-robin load balancing. At Netflix, a much more sophisticated load balancer wraps Eureka to provide weighted load balancing based on several factors like traffic, resource usage, error conditions etc to provide superior resiliency.負載均衡
簡單來講Eureka就是Netflix開源的一款提供服務註冊和發現的產品,而且提供了相應的Java客戶端。分佈式
其實有點不太同樣,Spring Cloud Netflix提供的膠水代碼更換了一些初始化配置,而且去掉了一些不合理的例如單實例EurekaServer服務等待時間,還增長了更人性化的界面:ide
從設計思路上看,Eureka是AP型設計,ZOOKEEPER是CP型設計:
綜上所述,Eureka適合做爲服務註冊發現中心,Zookeeper適合更普遍的分佈式協調服務
比較細節的架構圖以下所示,以後的文章咱們會詳細解釋:
注意,這個和官網的不同,在SpringCloud環境下,context-path就是eureka
header 1 | header 2 |
---|---|
row 1 col 1 | row 1 col 2 |
row 2 col 1 | row 2 col 2 |
Operation | HTTP action(針對SpringCloudNetflix環境下啓動的Eureka) | Description |
---|---|---|
註冊新服務實例或者修改實例基本信息(就是InstanceInfo類) | POST /eureka/apps/appID | Input:JSON/XMLpayload HTTPCode: 204 on success |
撤銷刪除服務實例 | DELETE /eureka/apps/appID/instanceID | HTTP Code: 200 on success |
實例心跳 | PUT /eureka/apps/appID/instanceID | HTTP Code:* 200 on success * 404 ifinstanceIDdoesn’t exist |
查詢全部服務實例列表 | GET /eureka/apps | HTTP Code: 200 on success Output:JSON/XML |
查詢某個服務的實例列表 | GET /eureka/apps/appID | HTTP Code: 200 on success Output:JSON/XML |
查詢某個服務某個實例信息 | GET /eureka/apps/appID/instanceID | HTTP Code: 200 on success Output:JSON/XML |
查詢某個實例信息 | GET /eureka/instances/instanceID | HTTP Code: 200 on success Output:JSON/XML |
將某個實例設置爲下線,這個和刪除不一樣,若是你手動調用刪除,但若是客戶端還活着,定時任務仍是會將實例註冊上去。可是改爲這個狀態,定時任務更新不了這個狀態 | PUT /eureka/apps/appID/instanceID/status?value=OUT_OF_SERVICE | HTTP Code:* 200 on success * 500 on failure |
下線狀態恢復 | DELETE /eureka/apps/appID/instanceID/status?value=UP (The value=UP is optional, it is used as a suggestion for the fallback status due to removal of the override) | HTTP Code:* 200 on success * 500 on failure |
更新元數據(這個不是InstanceInfo,是本身能夠往裏面自定義的數據) | PUT /eureka/apps/appID/instanceID/metadata?key=value | HTTP Code: * 200 on success * 500 on failure |
查詢某個VIP下的全部實例 | GET /eureka/vips/vipAddress | * HTTP Code: 200 on success Output:JSON/XML * 404 if thevipAddressdoes not exist. |
查詢某個SVIP下的全部實例 | GET /eureka/svips/svipAddress | * HTTP Code: 200 on success Output:JSON/XML * 404 if thesvipAddressdoes not exist. |
下一篇,咱們會詳細分析Eureka一些流程