1.1 SpringCloud介紹
1.1.1 微服務架構演化
簡而言之,微服務就是開發一組小型服務的方式來開發一個獨立的應用系統,每個小型服務都運行在自己的進程中,並采用HTTP資源API輕量級的機制來互相通信。這些服務圍繞業務功能進行構建,並能通過全自動的部署機制來進行獨立部署。這些微服務可以使用不同的語言來編寫,並且可以使用不同的數據庫存儲技術。
其實微服務就是在業務垂直拆分的基礎上,拆分的粒度更細。
1.1.2 微服務的優點
1. 易於開發和維護
業務分拆,一個微服務只關注一個特定的業務功能,所以它的業務清晰、代碼量較少。開發和維護單個微服務相對簡單。每個微服務業務復雜度低,方便理解、維護和調試。整個應用由若干個微服務構成。
2. 單個微服務啟動快
單個微服務代碼量少,啟動比龐大的項目要快。
3. 故障隔離
某個服務宕機,其他服務照常使用。單體項目就可能發生雪崩,造成整個系統宕機。
4. 局部修改容易部署
傳統單體項目修改一個功能就需要重新部署整個應用,而微服務只需對需要修改的服務重新部署,其他服務無需停止,甚至不相關的業務仍然可以繼續執行。
5. 技術棧不受限
在微服務中,支持技術異構,可以根據軟件團隊擅長的技術去實現,如java、c#、c、php等,也支持異構數據庫mysql、oracle、sqlServer等。
1.1.3 定義
Spring Cloud provides tools for developers to quickly build some of the common patterns in distributed systems (e.g. configuration management, service discovery, circuit breakers, intelligent routing, micro-proxy, control bus, one-time tokens, global locks, leadership election, distributed sessions, cluster state). Coordination of distributed systems leads to boiler plate patterns, and using Spring Cloud developers can quickly stand up services and applications that implement those patterns. They will work well in any distributed environment, including the developer's own laptop, bare metal data centres, and managed platforms such as Cloud Foundry.
Spring Cloud就是一個全家桶,整合了市面上最好最先進的技術,形成一個工具集,並簡化其中的操作,引領編程新方式。
1.1.4 官網
官網: http://projects.spring.io/spring-cloud/
手冊: http://cloud.spring.io/spring-cloud-static/Dalston.SR2/
中文: https://springcloud.cc/
1.1.5 核心功能
l configuration management 配置中心
l service discovery 服務發現
l circuit breakers 斷路器
l intelligent routing 智能路由
l micro-proxy 微代理
l control bus 控制總線
l one-time tokens 一次性令牌
l global locks 全局鎖
l leadership election 選舉算法
l distributed sessions 分布式會話
l cluster state 集群狀態
1.1.6 核心組件架構圖
1.1.7 規划內容和步驟
l 注冊中心Eureka eureka + provider-user + consumer-client
l 前端負載均衡Ribbon consumer-ribbon
l RESTFul簡易封裝 consumer-ribbon-feign
l 斷路器支持 consumer-ribbon-feign-hystrix
l API網關 Zuul gateway-zuul
l 異構開發語言Sidecar sidecar + nodejs
l 配置中心config configserver+ consumer-ribbon-feign-hystrix