跟大家介紹一下關(guān)于Spring Cloud Consul

Spring Cloud Consul項目是針對Consul的服務(wù)治理實現(xiàn)。Consul是一個分布式高可用的系統(tǒng),它包含多個組件,但是作為一個整體,在微服務(wù)架構(gòu)中為我們的基礎(chǔ)設(shè)施提供服務(wù)發(fā)現(xiàn)和服務(wù)配置的工具。它包含了下面幾個特性:

服務(wù)發(fā)現(xiàn)

健康檢查

Key/Value存儲

多數(shù)據(jù)中心

由于Spring Cloud Consul項目的實現(xiàn),我們可以輕松的將基于Spring Boot的微服務(wù)應(yīng)用注冊到Consul上,并通過此實現(xiàn)微服務(wù)架構(gòu)中的服務(wù)治理。

到此為止,我們將eureka-client轉(zhuǎn)換為基于consul服務(wù)治理的服務(wù)提供者就完成了。前文我們已經(jīng)有提到過服務(wù)發(fā)現(xiàn)的接口DiscoveryClient是Spring Cloud對服務(wù)治理做的一層抽象,所以可以屏蔽Eureka和Consul服務(wù)治理的實現(xiàn)細節(jié),我們的程序不需要做任何改變,只需要引入不同的服務(wù)治理依賴,并配置相關(guān)的配置屬性就能輕松的將微服務(wù)納入Spring Cloud的各個服務(wù)治理框架中。

下面可以嘗試讓consul的服務(wù)提供者運行起來。這里可能讀者會問,不需要創(chuàng)建類似eureka-server的服務(wù)端嗎?由于Consul自身提供了服務(wù)端,所以我們不需要像之前實現(xiàn)Eureka的時候創(chuàng)建服務(wù)注冊中心,直接通過下載consul的服務(wù)端程序就可以使用。

Atlas:

==> Log data will now streaminas it occurs:

2017/06/22 07:50:54 [INFO] raft: Initial configuration (index=1): [{Suffrage:Voter ID:127.0.0.1:8300 Address:127.0.0.1:8300}]

2017/06/22 07:50:54 [INFO] raft: Node at 127.0.0.1:8300 [Follower] entering Follower state (Leader:"")

2017/06/22 07:50:54 [INFO] serf: EventMemberJoin: Lenovo-zhaiyc 127.0.0.1

2017/06/22 07:50:54 [INFO] consul: Adding LAN server Lenovo-zhaiyc (Addr: tcp/127.0.0.1:8300) (DC: dc1)

2017/06/22 07:50:54 [INFO] serf: EventMemberJoin: Lenovo-zhaiyc.dc1 127.0.0.1

2017/06/22 07:50:54 [INFO] consul: Adding WAN server Lenovo-zhaiyc.dc1 (Addr: tcp/127.0.0.1:8300) (DC: dc1)

2017/06/22 07:51:01 [ERR] agent: failed to sync remote state: No cluster leader

2017/06/22 07:51:02 [WARN] raft: Heartbeat timeout from""reached, starting election

2017/06/22 07:51:02 [INFO] raft: Node at 127.0.0.1:8300 [Candidate] entering Candidate stateinterm 2

2017/06/22 07:51:02 [DEBUG] raft: Votes needed: 1

2017/06/22 07:51:02 [DEBUG] raft: Vote granted from 127.0.0.1:8300interm 2. Tally: 1

2017/06/22 07:51:02 [INFO] raft: Election won. Tally: 1

2017/06/22 07:51:02 [INFO] raft: Node at 127.0.0.1:8300 [Leader] entering Leader state

2017/06/22 07:51:02 [INFO] consul: cluster leadership acquired

2017/06/22 07:51:02 [INFO] consul: New leader elected: Lenovo-zhaiyc

2017/06/22 07:51:02 [DEBUG] consul: reset tombstone GC to index 3

2017/06/22 07:51:02 [INFO] consul: member'Lenovo-zhaiyc'joined, marking health alive

2017/06/22 07:51:02 [INFO] agent: Synced service'consul'

2017/06/22 07:51:02 [DEBUG] agent: Node infoinsync

consul服務(wù)端啟動完成之后,我們再將之前改造后的consul服務(wù)提供者啟動起來。consul與eureka一樣,都提供了簡單的ui界面來查看服務(wù)的注冊情況:



從現(xiàn)在開始,我這邊會將近期研發(fā)的springcloud微服務(wù)云架構(gòu)的搭建過程和精髓記錄下來,幫助更多有興趣研發(fā)spring cloud框架的朋友,希望可以幫助更多的好學(xué)者。大家來一起探討spring cloud架構(gòu)的搭建過程及如何運用于企業(yè)項目。源碼來源

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容