Spring Cloud 5分鐘搭建教程(附上一個分布式日志系統項目作為參考) - 推薦

http://blog.csdn.net/lc0817/article/details/53266212/

?

https://github.com/leoChaoGlut/log-sys

上面是我基于Spring Cloud ,Spring Boot 和 Docker 搭建的一個分布式日志系統.

目前已在我司使用. 想要學習Spring Cloud, Spring Boot以及Spring 全家桶的童鞋,可以參考學習,如果覺得好,star 一下吧~

?

<<<< 20170602 <<<<?

新增Spring Cloud [ Bus, Sleuth, Config, Stream ]教程:

Github:?https://github.com/leoChaoGlut/spring-cloud-tutorial

>>>>?20170602 >>>>?

?

<<<< 20170608 <<<<?

Ribbon源碼解析及常見問題:?http://blog.csdn.net/lc0817/article/details/72886721

>>>>?20170608 >>>>?

1.前言:

1.1.以下內容是我通過閱讀官方文檔,并成功實踐后的經驗總結,希望能幫助你更快地理解和使用Spring Cloud.?

1.2.默認讀者已經熟練掌握Spring 全家桶,Spring Boot和注解開發.

1.3.陸續更新

?

2.開發環境:?@Deprecated

2.1.開發工具:idea

2.2.開發環境:jdk1.7

2.3.Spring版本:

2.3.1.Spring Boot :1.4.0 release

2.3.2.Spring Cloud :?Camden SR2

?

3.demo:(獻給急于速成的各位大兄弟): demo地址:?https://github.com/leoChaoGlut/spring-cloud-demo

3.1.服務注冊demo:

3.1.1.創建工程模塊,如圖所示

3.1.2.將官方提供的maven依賴,加入pom.

[html]?view plain?copy
?
  1. <?xml?version="1.0"?encoding="UTF-8"?>??
  2. <project?xmlns="http://maven.apache.org/POM/4.0.0"??
  3. ?????????xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"??
  4. ?????????xsi:schemaLocation="http://maven.apache.org/POM/4.0.0?http://maven.apache.org/xsd/maven-4.0.0.xsd">??
  5. ????<modelVersion>4.0.0</modelVersion>??
  6. ??
  7. ????<groupId>demo</groupId>??
  8. ????<artifactId>spring-cloud-demo</artifactId>??
  9. ????<packaging>pom</packaging>??
  10. ????<version>1.0-SNAPSHOT</version>??
  11. ??
  12. ????<modules>??
  13. ????????<module>discovery</module>??
  14. ????????<module>service0</module>??
  15. ????????<module>service1</module>??
  16. ????</modules>??
  17. ??
  18. ????<!--以下dependency來自官方-->??
  19. ????<parent>??
  20. ????????<groupId>org.springframework.boot</groupId>??
  21. ????????<artifactId>spring-boot-starter-parent</artifactId>??
  22. ????????<version>1.4.0.RELEASE</version>??
  23. ????</parent>??
  24. ??
  25. ????<dependencyManagement>??
  26. ????????<dependencies>??
  27. ????????????<dependency>??
  28. ????????????????<groupId>org.springframework.cloud</groupId>??
  29. ????????????????<artifactId>spring-cloud-dependencies</artifactId>??
  30. ????????????????<version>Camden.SR2</version>??
  31. ????????????????<type>pom</type>??
  32. ????????????????<scope>import</scope>??
  33. ????????????</dependency>??
  34. ????????</dependencies>??
  35. ????</dependencyManagement>??
  36. ??
  37. ????<dependencies>??
  38. ????????<dependency>??
  39. ????????????<groupId>org.springframework.cloud</groupId>??
  40. ????????????<artifactId>spring-cloud-starter-config</artifactId>??
  41. ????????</dependency>??
  42. ????????<dependency>??
  43. ????????????<groupId>org.springframework.cloud</groupId>??
  44. ????????????<artifactId>spring-cloud-starter-eureka</artifactId>??
  45. ????????</dependency>??
  46. ????????<dependency>??
  47. ????????????<groupId>org.springframework.boot</groupId>??
  48. ????????????<artifactId>spring-boot-devtools</artifactId>??
  49. ????????????<optional>true</optional>??
  50. ????????</dependency>??
  51. ????</dependencies>??
  52. ??
  53. ??
  54. </project>??

3.1.3.如圖步驟,完成Discovery

?

3.1.4.如圖步驟完成Service0,Service1類似

3.1.5.簡單到爆炸有沒有...........,接下來先啟動Discovery,然后啟動Service0和Service1

3.1.6.打開瀏覽器,訪問 localhost:8080 ,8080是Discovery里配置的端口號.一切順利的話,可以看到:

3.1.7.已經成功注冊了service0,service1兩個服務

3.2.網關demo: 光是注冊了服務還不行,這里可以再配一個網關,讓服務調用有統一的入口.?

3.2.1.通過上圖配置后,首先啟動Discovery,其次的服務和網關啟動順序隨意.通過訪問localhost:8083/service0/service0,即可看到,gateway幫我們轉發了請求.

?

3.3.Feign:一個可以把遠程服務提供方的 rest 接口變成本地方法調用的Spring Cloud組件

舉個栗子:

現在有2個服務,service0, service1

service0提供了一個test接口,

那么這時候,如果service1需要的調用service0,除了通過網關(zuul)調用,還可以使用Feign,來把service0的遠程接口,變為本地方法調用.如圖:

4.feign?+ ribbon + hystrix

簡介:

hystrix: 以切面為原理,可以在不入侵業務代碼的情況下,給方法加上超時等指標,并且可以在超出設置的指標后,調用指定的fallback方法,進行失敗回調處理.

ribbon: 客戶端負載均衡, 我曾經也寫了一個類似的東西(https://github.com/leoChaoGlut/ServiceDIscoveryAndRegistry/tree/master/doc),不過后來發現spring cloud已經有成熟的,現成的常用組件,所以就放棄了.哈哈.... 老式的,無注冊中心的服務調用,是通過url來實現的,但是ribbon可以讓我們只需要提供服務名,就可以調用到多實例的服務,并且在客戶端做一個負載分發,減輕服務端負載的壓力.

feign: 給你以Http的形式,帶來RPC般的體驗.

?

?

認真看圖和代碼,即可快速上手 feign + ribbon + hystrix 配置

細看spring cloud, feign,ribbon,hystrix的官方文檔,加上源碼的閱讀,即可掌握如何使用spring cloud 配置 這三個組件.

?

5.分布式應用日志追蹤: spring cloud sleuth:

http://blog.csdn.net/lc0817/article/details/72829935

6.分布式配置中心: Spring Cloud Config

http://blog.csdn.net/lc0817/article/details/72833007

7.消息總線: Spring Cloud Bus:

http://blog.csdn.net/lc0817/article/details/72836236

8.Netflix 基本組件:Feign Ribbon Hystrix 詳細整合

http://blog.csdn.net/lc0817/article/details/72875195

9.流處理:Spring Cloud Stream

http://blog.csdn.net/lc0817/article/details/72956321

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/391077.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/391077.shtml
英文地址,請注明出處:http://en.pswp.cn/news/391077.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

51nod1832(二叉樹/高精度模板+dfs)

題目鏈接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId1832 題意: 中文題誒~ 思路: 若二叉樹中有 k 個節點只有一個子樹, 則答案為 1 << k. 詳情參見:http://blog.csdn.net/gyhguoge01234/article/details/77836484 代碼: 1 #include <iostream&g…

重學TCP協議(11)TFO(Tcp Fast Open)

1. TFO 為了改善web應用相應時延&#xff0c;google發布了通過修改TCP協議利用三次握手時進行數據交換的TFO(TCP fast open&#xff0c;RFC 7413)。 TFO允許在TCP握手期間發送和接收初始SYN分組中的數據。如果客戶端和服務器都支持TFO功能&#xff0c;則可以減少建立到同一服…

[網絡安全] 遠程登錄

遠程登錄方式: 1.圖像化遠程登錄 做法: 運行"窗口"輸入 "mstsc " 輸入ip地址 注意: 被遠程計算機&#xff0c;必須打開遠程登錄服務: 信息面板–系統–允許遠程訪問。被遠程計算機&#xff0c;必須存在擁有遠程桌面權限的用戶。 2.命令行遠程登錄 teln…

外星人圖像和外星人太空船_衛星圖像:來自太空的見解

外星人圖像和外星人太空船By Christophe Restif & Avi Hoffman, Senior Software Engineers, Crisis Response危機應對高級軟件工程師Christophe Restif和Avi Hoffman Editor’s note: In 2019, we piloted a new feature in Search SOS Alerts for major California wild…

chrome恐龍游戲_如何玩沒有互聯網的Google Chrome恐龍游戲-在線和離線

chrome恐龍游戲Several years ago, Google added a fun little Easter egg to Chrome: if your internet went down and you tried to visit a web page, youd see the message "Unable to connect to the Internet" or "No internet" with a little pixi…

Hotpatch潛在的安全風險

屎蛋 2016/06/22 10:11author:[email protected]0x00 “Hotpatch”簡介IOS App的開發者們經常會出現這類問題&#xff1a;當一個新版本上線后發現存在一個嚴重的bug&#xff0c;有可能因為一個邏輯問題導致支付接口存在被薅羊毛的風險&#xff0c;這個時候能做的只能是趕快修復…

spring中@Inject和@Autowired的區別?分別在什么條件下使用呢?

問題&#xff1a;spring中Inject和Autowired的區別&#xff1f;分別在什么條件下使用呢&#xff1f; 我在瀏覽SpringSource上的一些博客&#xff0c;在其他一個博客中&#xff0c;那個作者用了Inject&#xff0c;但是我覺得他用Autowired也行 下面是一部分代碼&#xff1a; …

Objective-C語言的動態性

Objective-C具有相當多的動態特性&#xff0c;基本的&#xff0c;也是經常被提到和用到的有動態類型&#xff08;Dynamic typing&#xff09;&#xff0c;動態綁定&#xff08;Dynamic binding&#xff09;和動態加載&#xff08;Dynamic loading&#xff09; 一、編譯時和運行…

內存泄漏和內存溢出的區別

原文地址https://www.zhihu.com/question/40560123 簡單來說&#xff0c;操作系統就像資源分配人員&#xff0c;你要使用內存的時候分給你&#xff0c;你用完了還給它。如果你使用了沒有分配給你的內存就是內存溢出&#xff0c;如果你用完了沒有還就是內存泄漏。會引起的問題&a…

怎么注銷筆記本icloud_如何在筆記本電腦或臺式機的Web瀏覽器中在線查看Apple iCloud照片

怎么注銷筆記本icloudPicture this: you just returned from a beautiful vacation and want to show all those gorgeous photos to your family. But your phone just died. And since youre at a family dinner your laptop is nowhere to be found.想象一下&#xff1a;您剛…

棒棒糖 宏_棒棒糖圖表

棒棒糖 宏AKA: lollipop plot又名&#xff1a;棒棒糖情節 WHY: a lollipop chart (LC) is a handy variation of a bar chart where the bar is replaced with a line and a dot at the end. Just like bar graphs, lollipop plots are used to make comparisons between diff…

ubuntu上如何安裝tomcat

1. 在官網下載linux里面的tomcat 2. 放到DownLoads下面--把tomcat的壓縮包放到DownLoads3. sudo mkdir /usr/local/tomcat/ -在usr/local/路徑下新建一個tomcat的文件夾4 sudo tar zxvf tomcat。。。。tar.gz -C /usr/local/tomcat/---把解壓后的tomcat放到usr/local/下的tomca…

leetcode 1734. 解碼異或后的排列(位運算)

給你一個整數數組 perm &#xff0c;它是前 n 個正整數的排列&#xff0c;且 n 是個 奇數 。 它被加密成另一個長度為 n - 1 的整數數組 encoded &#xff0c;滿足 encoded[i] perm[i] XOR perm[i 1] 。比方說&#xff0c;如果 perm [1,3,2] &#xff0c;那么 encoded [2,…

ZooKeeper3.4.5-最基本API開發

2019獨角獸企業重金招聘Python工程師標準>>> package cn.itcast.bigdata.zk;import java.io.IOException; import java.util.List;import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.WatchedEven…

字符串轉換整數python_將Python字符串轉換為Int:如何在Python中將字符串轉換為整數

字符串轉換整數pythonUnlike many other programming languages out there, Python does not implicitly typecast integers (or floats) to strings when you concatenate them to strings.與現有的許多其他編程語言不同&#xff0c;Python在將整數連接到字符串時不會隱式地將…

理解Java里面的必檢異常和非必檢異常

問題&#xff1a;理解Java里面的必檢異常和非必檢異常 Joshua Bloch在"Effective Java"里面說過 在可恢復的條件下和編程錯誤導致的運行時錯誤時&#xff0c;使用必檢異常&#xff08;第二版的第52頁&#xff09; 讓我們來看一下我對這個的正確理解吧 下面是我對…

使用vim打開文件的16進制形式,編輯和全文替換

1、先用vim打開文件的二進制形式&#xff0c;如果不以二進制可能會產生轉換錯誤。 vim -b file-to-open.dat 2、用xxd把文件轉換成十六進制格式 :%!xxd 現在就可以對待普通文本一樣查看和編輯二進制文件了。 3、vim 單文件替換方法 :%s/old/new/gc 全文執行替換,詢問是…

nlp自然語言處理_不要被NLP Research淹沒

nlp自然語言處理自然語言處理 (Natural Language Processing) 到底是怎么回事&#xff1f; (What is going on?) NLP is the new Computer VisionNLP是新的計算機視覺 With enormous amount go textual datasets available; giants like Google, Microsoft, Facebook etc have…

opencv 隨筆

裝環境好累&#xff0c;python3.6&#xff0c;opencv3.4 好不容易裝好了&#xff0c;結果 addweight的時候總是報錯 The operation is neither array op array (where arrays have the same size and the same number of channels), nor array op scalar, nor scalar op array …

js打開飛行模式_什么是飛行模式? 它有什么作用?什么時候應該打開它?

js打開飛行模式If youve flown on an airplane in the last decade and you have a smart phone, youve likely had to put that phone in airplane mode before the plane takes off.如果您在過去的十年中乘坐過飛機&#xff0c;并且擁有一部智能手機&#xff0c;那么您可能必…