買這商品的人也買了...
-
$403企業應用架構模式 (Patterns of Enterprise Application Architecture)
-
$414$393 -
$450$297 -
$305MERN 全棧開發 : 使用 Mongo Express React 和 Node (Pro MERN Stack: Full Stack Web App Development with Mongo, Express, React, and Node)
-
$297深入淺出 Spring Boot 2.x
-
$774$735 -
$607Spring Cloud 微服務和分佈式系統實踐
-
$709深入解析 CSS (CSS in Depth)
-
$650$429 -
$400$264 -
$740高性能 Linux 服務器運維實戰:shell 編程、監控告警、性能優化與實戰案例
-
$1,000$660 -
$954$906 -
$654$621 -
$550$363 -
$301Netty 實戰
-
$534$507 -
$880$581 -
$714$678 -
$450$297 -
$690$455 -
$450$297 -
$690$455 -
$580$383 -
$708$673
相關主題
商品描述
本書從動態代理模式、Reactor模式、三大限流策略等知識入手,
深入淺出地剖析Spring Cloud+Nginx系統架構的核心原理以及Web高並發開發。
全書從基礎設計模式和基礎原理出發,理論與實戰相結合,系統和詳盡地介紹Spring Cloud + Nginx高並發核心編程。
本書共10章,前6章剖析Feign高並發RPC的底層原理,解析Hystrix高性能配置的核心選項,闡述Hystrix滑動窗口的核心原理。
後4章介紹Nginx的核心原理及其配置,並結合秒殺場景實現Spring Cloud秒殺、
Spring Cloud+Nginx Lua秒殺,為廣大Java開發者提供一個全面學習高並發開發的實戰案例。
這些知識為廣大的Java工程師解決日常在後台開發中遇到的高並發、高性能問題打下堅實的技術基礎。‘
作者簡介
作者:蓋茨(Brian Goetz) (美國)Tim Peierls (美國)Joshua Bloch 等譯者:童雲蘭等本書作者都是Java Community Process JSR 166專家組(並發工具)的主要成員,並在其他很多JCP專家組裡任職。 Brian Goetz有20多年的軟件諮詢行業經驗,並著有至少75篇關於Java開發的文章。 Tim Peierls是“現代多處理器”的典範,他在BoxPop.biz、唱片藝術和戲劇表演方面也頗有研究。 Joseph Bowbeer是一個Java ME專家,他對並發編程的興趣始於Apollo計算機時代。 David Holmes是《The Java Programming Language》一書的合著者,任職於Sun公司。 Joshua Bloch是Google公司的首席Java架構師,《Effective Java》一書的作者,並參與著作了《Java Puzzlers》。 Doug Lea是《Concurrent Programming》一書的作者,紐約州立大學 Oswego分校的計算機科學教授。
目錄大綱
前言
1章Spring Cloud+Ngin高並發核心編程的學習準備........................ 1
1.1 Spring Cloud+Ngin架構的主要組件.. ...................................... 1
1.2 Spring Cloud和Spring Boot的版本選擇.. ...................................... 3
1.3 Spring Cloud微服務開發所涉及的中間件..................................... 4
1.4 Spring Cloud微服務開發和自驗證環境.. ...................................... 6
1.4.1開發和自驗證環境的系統選項和環境變量配置........................................ 6
1.4.2使用Fiddler工具抓包和查看報文........................................ 7
1.5 crazy -springcloud微服務開發腳手........................................ 9
1.6以秒殺作為Spring Cloud+Ngin的實戰案例........................................ 10
2章Spring Cloud入門實戰........................................ 12
2.1 Eureka服務註冊與發現........................................ 13
2.1.1什麼是服務註冊與發現........................................ 13
2.1.2 Eureka Server註冊中心........................................ 14
2.1.3服務提供者的創建和配置........................................ 19
2.1.4服務提供者的續約(心跳) ........................................ 22
2.1 .5服務提供者的健康狀態........................................ 24
2.1 .6 Eureka自我保護模式與失效Provider的快速剔除.................................... 28
2.2 Config配置中心........................................ 32
2.2.1 config-server服務端組件........................................ 32
2.2.2 config-client客戶端組件........................................ 35
2.3微服務的RPC遠程調用........................................ 36
2.3.1 RESTful風格簡介........................................ 36
2.3.2 RestTemplate遠程調用........................................ 37
2.3.3 Feign遠程調用........................................ 38
2.4 Feign+Ribbon實現客戶端負載均衡........................................ 40
2.4.1 Spring Cloud Ribbon基礎.. ...................................... 41
2.4.2 Spring Cloud Ribbon的負載均衡策略. ....................................... 43
2.4.3 Spring Cloud Ribbon的常用配置. ....................................... 45
2.5 Feign+Hystri實現RPC調用保護.. ...................................... 50
2.5.1 Spring Cloud Hystri失敗回... ..................................... 51
2.5.2分佈式系統面臨的雪崩難題.. ...................................... 55
2.5.3 Spring Cloud Hystri熔斷器........................................ 56
3章Spring Cloud RPC遠程調用核心原理........................................ 61
3.1代理模式與RPC客戶端實現類........................................ 61
3.1 .1客戶端RPC遠程調用實現類的職責....................................... . 61
3.1.2簡單的RPC客戶端實現類...................................... .. 63
3.1.3從基礎原理講起:代理模式與RPC客戶端實現類.............................. .......... 67
3.1.4使用動態代理模式實現RPC客戶端類........................... ............. 70
3.1.5 JDK動態代理機制的原理........................... ............. 74
3.2模擬Feign RPC動態代理的實現............................ ............ 77
3.2.1模擬Feign的方法處理器MethodHandler ........................... ............. 78
3.2.2模擬Feign的調用處理器InvocationHandler ...................................... 80
3.2 .3模擬Feign的動態代理RPC的執行流程....................................... . 83
3.2.4模擬動態代理RPC遠程調用的測試..................................... ... 83
3.2.5 Feign彈性RPC客戶端實現類.................................... .... 85
3.3 Feign彈性RPC客戶端的重要組件..................................... ... 86
3.3.1演示用例說明........................................ 86
3.3.2 Feign的動態代理RPC客戶端實例...................................... .. 88
3.3.3 Feign的調用處理器InvocationHandler ...................................... .. 89
3.3.4 Feign的方法處理器MethodHandler ...................................... .. 91
3.3.5 Feign的客戶端組件....................................... . 94
3.4 Feign的RPC動態代理實例的創建流程........................................ 97
3.4.1 Feign的整體運作流程........................................ 98
3.4.2 RPC動態代理容器實例的FactoryBean工廠類...................................... .. 99
3.4.3 Feign.Builder建造者容器實例..................................... ... 102
3.4.4默認的RPC動態代理實例的創建流程.................................. ...... 105
3.4.5 Contract遠程調用協議規則類.................................. ...... 108
3.5 Feign遠程調用的執行流程.................................... .... 110
3.5.1與FeignInvocationHandler相關的遠程調用執行流程.................................. . 110
3.5.2與HystriInvocationHandler相關的遠程調用執行流程................................. 111
3.5.3 Feign遠程調用的完整流程及其特性........................................ 114
3.6 HystriFeign動態代理實例的創建流程........................................ 115
3.6 .1 HystriFeign.Builder建造者容器實例........................................ 115
3.6.2配置HystriFeign.Builder建造者容器實例...................................... 116
3.7 feign.Client客戶端容器實例........................................ 117
3.7 .1裝配LoadBalancerFeignClient負載均衡容器實例................................ 117
3.7.2裝配ApacheHttpClient負載均衡容器實例........................................ 119
3.7.3裝配OkHttpClient負載均衡容器實例........................................ 121
3.7.4裝配Client.Default負載均衡容器實例................................ 122
4章RJava響應式編程框架........ ................................ 124
4.1從基礎原理講起:觀察者模式....... ................................. 124
4.1.1觀察者模式的基礎原理........................................ 124
4.1.2觀察者模式的經典實現........................................ 125
4.1.3 RJava中的觀察者模式........................................ 127
4.1.4 RJava的不完整回調........................................ 130
4.1 .5 RJava的函數式編程........................................ 132
4.1. 6 RJava的作符........................................ 134
4.2創建型作符........................................ 134
4.2.1 just作符.. ...................................... 135
4.2.2 from作符..... ................................... 135
4.2.3 range作符........ ................................ 136
4.2.4 interval作符........... ............................. 137
4.2.5 defer作符........................................ 138
4.3過濾型作符........................................ 139
4.3.1 filter作符. ....................................... 139
4.3.2 distinct作符.... .................................... 140
4.4轉換型作符........ ................................ 141
4.4.1 map作符........... ............................. 141
4.4.2 flatMap作符.............. .......................... 142
4.4.3 scan作符................. ....................... 144
4.5聚合作符...................... ..................146
4.5.1 count作符......................... ............... 146
4.5.2 reduce作符............................ ............ 147
4.6其他作符................................. ....... 149
4.6.1 take作符........................................ 149
4.6.2 window作符........................................ 150
4.7 RJava的Scheduler調度器........................................ 153
4.8背壓...... .................................. 155
4.8.1什麼是背壓問題....... ................................. 155
4.8.2背壓問題的幾種應對模式..... ................................... 158
5章Hystri RPC保護的原理....... ................................. 162
5.1 RPC保護的目標........... ............................. 162
5.2 HystriCommand簡介................. ....................... 162
5.2.1 HystriCommand的使用.................... .................... 163
5.2.2 HystriCommand的配置內容和方式.................... .................... 166
5.3 HystriCommand命令的執行方法........................................ 168
5.3.1 eecute()方法........................................ 168
5.3.2 queue( )方法........................................ 170
5.3.3 observe()方法........................................ 172
5.3.4 toObservable()方法.. ...................................... 173
5.3.5 HystriCommand的執行方法之間的關係........................................ 175
5.4 RPC保護之艙壁模式.. ...................................... 176
5.4.1什麼是艙壁模式... ..................................... 176
5.4.2 Hystri線程池隔離..... ................................... 178
5.4.3 Hystri線程池隔離配置...... .................................. 182
5.4.4 Hystri信號量隔離........ ................................ 184
5.5 RPC保護之熔斷器模式........................................ 188
5.5. 1熔斷器狀態變化的演示實例........................................ 189
5.5 .2熔斷器和滑動窗口的配置屬性........................................ 193
5.5.3 Hystri命令的執行流程........................................ 198
5.6 RPC監控之滑動窗口的實現原理........................................ 199
5.6.1 Hystri健康統計滑動窗口的模擬實現....................................... . 200
5.6.2 Hystri滑動窗口的核心實現原理...................................... .. 205
6章微服務網關與用戶身份識別...................................... .. 210
6.1 Zuul的基礎使用........................................ 211
6.2創建Zuul網關服務........................................ 211
6.2.1 Zuul路由規則配置........................................ 212
6.2.2過濾敏感請求頭部........................................ 214
6.2 .3路徑前綴的處理........................................ 215
6.3 Zuul過濾器........................................ 216
6.3.1 Zuul網關的過濾器類型........................................ 216
6.3.2實戰:用戶的黑名單過濾........................................ 217
6.4 Spring Security原理和實戰. ....................................... 221
6.4.1 Spring Security核心組件... ..................................... 221
6.4.2 Spring Security的請求認證處理流程.. ...................................... 224
6.4.3基於數據源的認證流程.. ...................................... 231
6.5 JWT+Spring Security進行網關安全認證.. ...................................... 237
6.5.1 JWT安全令牌規範詳解.. ...................................... 238
6.5.2 JWT+Spring Security認證處理流程........................................ 243
6.5.3 Zuul網關與UAA微服務的配合...................................... .. 250
6.5.4使用Zuul過濾器添加代理請求的用戶標識.................................. ...... 254
6.6服務提供者之間的會話共享關係................................. ....... 256
6.6.1分佈式Session的起源和實現方案............................... ......... 257
6.6.2 Spring Session的核心組件和存儲細節............................. ........... 258
6.6.3 Spring Session的使用和定制............................. ........... 259
6.6.4通過用戶身份標識查找Session ID ............................ ......... 261
6.6.5查找或創建分佈式Session ............................... ......... 263
6.6.6加載高速訪問數據到分佈式Session ............................. ........... 265
7章Ngin/OpenResty詳解........................................ 268
7.1 Ngin簡介........................................ 268
7.1.1正向代理與反向代理........................................ 269
7.1.2 Ngin的啟動與停止........................................ 270
7.1.3 Ngin的啟動命令和參數詳解........................................ 271
7.1.4 Linu下OpenResty的啟動、停止腳本........................................ 271
7.1.5 Windows下OpenResty的啟動、停止腳本........................................ 273
7.2 Ngin的核心原理........................................ 274
7.2.1 Reactor模型... ..................................... 274
7.2.2 Ngin的兩類進程.... .................................... 275
7.2.3 Ngin的模塊化設計..... ................................... 276
7.2.4 Ngin配置文件上下文結構........................................ 278
7.2 .5 Ngin的請求處理流程........................................ 280
7.2. 6 HTTP請求處理的11個階段........................................ 281
7.3 Ngin的基礎配置........................................ 286
7.3.1 events事件驅動配置........................................ 286
7.3.2虛擬主機配置. ....................................... 287
7.3.3錯誤頁面配置.... .................................... 289
7.3.4長連接相關配置...... .................................. 290
7.3.5訪問日誌配置......... ............................... 290
7.3.6 Ngin核心模塊內置變量.......... .............................. 291
7.4 location路由規則配置詳解............. ........................... 293
7.4.1 location語法詳解........................................ 293
7.4.2常用的location路由配置........................................ 296
7.5 Ngin的rewrite模塊指令........................................ 297
7.5.1 set指令.. ...................................... 298
7.5.2 rewrite指令...... .................................. 298
7.5.3 if條件指令......... ............................... 301
7.5.4 add_header指令............. ........................... 303
7.5.5指令的執行順序............... ......................... 304
7.6反向代理與負載均衡配置................ ........................ 305
7.6.1演示環境說明................... ..................... 305
7.6.2 proy_pass反向代理指令.................... .................... 306
7.6.3 proy_set_header請求頭設置指令................................... 308
7.6.4 upstream上游服務器組........................................ 309
7.6.5 upstream的上游服務器配置........................................ 311
7.6.6 upstream的負載分配方式. ....................................... 313
8章Ngin Lua編程..... ................................... 315
8.1 Ngin Lua編程的主要應用場景...... .................................. 315
8.2 Ngin Lua編程簡介.......... .............................. 315
8.2.1 ng_lua簡介.............. .......................... 315
8.2.2 Ngin Lua項目的創建............... ......................... 316
8.2.3 Lua項目的工程結構................ ........................ 317
8.2.4 Lua項目的啟動.................. ...................... 318
8.3 Lua開發基礎........................................ 319
8.3.1 Lua模塊的定義和使用........................................ 319
8.3.2 Lua模塊的使用........................................ 320
8.3.3 Lua的數據類型........................................ 322
8.3.4 Lua的字符串.. ...................................... 325
8.3.5 Lua的數組容器.... .................................... 326
8.3.6 Lua的控制結構...... .................................. 328
8.3.7 Lua的函數定義........ ................................ 331
8.3.8 Lua的面向對象編程......... ............................... 332
8.4 Ngin Lua編程基礎............. ........................... 333
8.4.1 Ngin Lua的執行原理.............. .......................... 334
8.4.2 Ngin Lua的配置指令........................................ 335
8.4 .3 Ngin Lua的內置常量和變量........................................ 339
8.5 Ngin Lua編程實例........................................ 341
8.5.1 Lua腳本獲取URL中的參數........................................ 341
8.5.2 Ngin Lua的內置方法........................................ 342
8.5.3通過ng.header設置HTTP響應頭........................................ 344
8.5. 4 Lua訪問Ngin變量........................................ 347
8.5.5 Lua訪問請求上下文變量........................................ 349
8.6重定向與內部子請求........................................ 350
8.6.1 Ngin Lua內部重定向........................................ 350
8.6.2 Ngin Lua外部重定向........................................ 352
8.6.3 ng.location.capture子請求........................................ 355
8.6.4 ng.location.capture_multi並發子請求...................................... .359
8.7 Ngin Lua作Redis ........................................ 361
8.7. 1 Redis的CRUD基本作........................................ 361
8.7.2實戰:封裝一個作Redis的基礎類........................................ 364
8.7.3在Lua中使用Redis連接池........................................ 367
8.8 Ngin Lua編程實戰案例........................................ 369
8.8. 1 Ngin+Redis進行分佈式訪問統計........................................ 369
8.8.2 Ngin+Redis+Java容器實現高並發訪問..................................... ... 370
8.8.3 Ngin+Redis實現黑名單攔截.................................... .... 375
8.8.4使用Ngin Lua共享內存........................................ 378
9章限流原理與實戰........................................ 380
9.1限流策略原理與參考實現........................................ 380
9.1.1 3種限流策略:計數器、漏桶和令牌桶..................................... ... 380
9.1.2計數器限流原理和Java參考實現................................... ..... 381
9.1.3漏桶限流原理和Java參考實現................................ ........ 384
9.1.4令牌桶限流原理和Java參考實現............................ ............ 386
9.2分佈式計數器限流............................... ......... 390
9.2.1實戰:Ngin Lua分佈式計數器限流............................ ............ 390
9.2.2實戰:Redis Lua分佈式計數器限流......................... ............... 394
9.3 Ngin漏桶限流詳解........................... ............. 397
9.4實戰:分佈式令牌桶限流........................................ 399
9.4.1分佈式令牌桶限流Lua腳本..................................... ... 399
9.4.2 Java分佈式令牌桶限流................................... ..... 402
9.4.3 Java分佈式令牌桶限流的自驗證.............................. .......... 406
10章Spring Cloud+Ngin秒殺實戰............................... ......... 409
10.1秒殺系統的業務功能和技術難點............................... ......... 409
10.1.1秒殺系統的業務功能................................ ........ 409
10.1.2秒殺系統面臨的技術難題................................ ........ 410
10.2秒殺系統的系統架構................................... ..... 411
10.2.1秒殺的分層架構.................................... .... 411
10.2.2秒殺的限流架構..................................... ... 413
10.2.3秒殺的分佈式鎖架構........................................ 414
10.2.4秒殺的削峰架構........................................ 415
10.3秒殺業務的參考實現........................................ 416
10.3.1秒殺的功能模塊和接口設計........................................ 416
10.3.2數據表和PO實體類設計........................................ 420
10.3. 3使用分佈式ID生成器........................................ 423
10.3. 4秒殺的控制層設計........................................ 424
10.3.5 service層邏輯:獲取秒殺令牌........................................ 426
10.3 .6 service層邏輯:執行秒殺下單........................................ 429
10.3.7秒殺的Lua腳本設計........................................ 434
10.3.8 BusinessEception定義........................................ 436
10.4 Zuul內部網關實現秒殺限流........................................ 439
10.5 Ngin高性能秒殺和限流...................................... 444
10.5.1 Lua腳本:獲取秒殺令牌........................................ 445
10.5.2 Lua腳本:執行令牌桶限流........................................ 448