雲原生Java:Spring Boot、Spring Cloud與Cloud Foundry彈性系統設計

Josh Long, Kenny Bastani

  • 出版商: 電子工業出版社
  • 出版日期: 2018-07-01
  • 定價: $768
  • 售價: $768
  • 貴賓價: 9.5$730
  • 語言: 簡體中文
  • 頁數: 600
  • 裝訂: 其他
  • ISBN: 7121342510
  • ISBN-13: 9787121342516
  • 相關分類: Java 相關技術

下單後立即進貨 (4週~6週)

商品描述

無論是傳統IT行業,還是互聯網行業,都正處於行業歷史上最劇烈的變革中 :大量的系統正在從傳統的IT架構轉向基於雲的架構, 開發模式也正在從開發和運維分工的傳統模式,逐漸轉向統一的“DevOps”模式。Java技術已經進入了新的生命周期,大量被用於構建現代的、基於雲的應用程序。 本書詳細闡述了開發雲原生應用程序的機遇和挑戰,明確指出了成功實現的方向,並且重點介紹了微服務框架Spring Boot。Spring Boot可以輕松創建任何粒度的 Spring服務,並部署到現代的容器環境中。本書主要面向正在使用 Spring Boot、SpringCloud和Cloud Foundry, 以便更快、更好地構建軟件的Java/JVM 開發人員。本書一共分為4個部分共15章。第1章和第2章介紹了雲原生思想產生的背景,然後介紹了Spring Foundry。第3章介紹瞭如何配置Spring Boot應用程序。第4章介紹瞭如何測試Spring應用程序,從如何測試最簡單的組件到測試分佈式系統。第5章介紹了可以將應用程序遷移到Cloud Foundry等雲平臺的輕量級重構方式。第6章介紹瞭如何使用Spring構建HTTP和RESTful服務。第7章介紹了在分佈式系統中控制請求進出的常用方法。第8章介紹瞭如何構建一個響應外部請求的服務。第9章介紹瞭如何使用Spring Data在Spring中管理數據。這為領域驅動的思想奠定了基礎。第10章介紹瞭如何使用Spring中事件驅動、消息中心化的能力,來集成分佈式服務和數據。第11章介紹瞭如何利用雲平臺(如Cloud Foundry)的能力來處理長期運行的工作。第12章介紹了在分佈式系統中管理狀態的一些方法。第13章介紹瞭如何構建具備可觀測性和可操作性的系統。第14章介紹瞭如何構建類似於Cloud Foundry平臺的服務代理。第15章介紹了持續交付背後的思想。

作者簡介

作者:(美)Josh Long(喬西 朗)、 Kenny Bastani(肯尼 巴斯塔尼)譯者:張若飛

Josh Long是一名Spring developer advocate,是InfoQ.com Java團隊的編輯。他也是多部著作的主要作者,如Spring Recipes,2nd Edition(Apress)。
Kenny Bastani是Pivotal的一名Spring developer advocate。作為一名開源貢獻者和軟件架構博主(WWW.kennybastani.com),他為軟件開發者提供關於構建事件驅動的微服務和無服務器架構方面的教程。他也在一些行業會議上做演講,如OSCON、SpringOne Platform和GOTO大會。
 

目錄大綱

前言(James Watters)............................................ ...........xv 
前言(Rod Johnson)................................. ....................... xvii 
前言......................... .................................................. ..... xix 
第Ⅰ部分基礎知識
第1章云原生應用程序................................ .......................... 3 
亞馬遜的故事.................... .................................................. ......................................... 3 
平台的承諾..... .................................................. .................................................. .......... 5 
模式...................................... .................................................. ...................................... 7
可擴展性............................................... .................................................. ...................... 7 
可靠性......................... .................................................. ................................................ 8 
敏捷性................................................. .................................................. ........................ 8 
Netflix的故事...................... .................................................. ....................................... 9 
微服務........ .................................................. .................................................. ..... 11 
拆分單體系統....................................... .................................................. ............. 12
Netflix OSS ................................................ .................................................. ....... 13 
雲原生Java ....................................... .................................................. ................ 14 
十二要素原則............................. .................................................. .............................. 14 
代碼庫................. .................................................. .............................................. 15 
依賴.. .................................................. .................................................. ............... 15 
配置................................. .................................................. .................................. 16 
x |目錄
後端服務............................................... .................................................. ............ 17 
構建、發布、運行................................ .................................................. ............ 17 
進程.................................... .................................................. ............................... 17 
端口綁定............... .................................................. ............................................ 18 
並發.... .................................................. .................................................. ............. 18 
易處理.................................. .................................................. ............................. 18
開發/生產環境一致............................................. .............................................. 19 
日誌.. .................................................. .................................................. ............... 19 
管理進程................................ .................................................. ........................... 19 
總結..................... .................................................. .................................................. ... 20 

第2章訓練營:Spring Boot和Cloud Foundry......................21 
什麼是Spring Boot ........ .................................................. ........................................... 21
Spring Initializr入門............................................... .................................................. .. 21 
Spring Tool Suite入門........................................... .................................................. ... 30 
安裝Spring Tool Suite(STS)....................................... ...................................... 30 
使用Spring Initializr創建一個新項目.... .................................................. .......... 31 
Spring指南大全.................................... .................................................. .................... 36 
遵循STS中的指南........................ .................................................. ................... 38
配置................................................. .................................................. ......................... 40 
Cloud Foundry平台..................... .................................................. ............................. 52 
總結................... .................................................. .................................................. ..... 66 

第3章符合十二要素程序風格的配置................................. ...... 67 
令人迷惑的“配置”合併................................... .................................................. ...... 67 
Spring框架對配置的支持..................................... .................................................. .... 67 
PropertyPlaceholderConfigurer ............................................ ................................ 68
Environment接口和@Value註解............................................ ........................... 69 
Profile ..................... .................................................. ........................................... 71 
啟動配置.... .................................................. .................................................. ............. 73 
使用Spring Cloud Config Server進行中心化、日誌型的配置....................... ............ 76 
Spring Cloud Config Server ................................. ................................................ 76 
Spring Cloud Config客戶端.............................................. .................................. 78 
安全.............. .................................................. .................................................. ... 79
目錄| xi 
可刷新的配置........................................... .................................................. ................ 79 
總結................................ .................................................. .......................................... 83 

第4章測試... .................................................. ................ 85 
測試的構成.............................. .................................................. ................................. 86 
在Spring Boot中進行測試.......... .................................................. ............................. 86 
集成測試.................. .................................................. ................................................. 88
測試切片................................................ .................................................. ........... 89 
測試中的Mock .................................. .................................................. ............... 89 
使用@SpringBootTest中的Servlet容器........................... ................................. 93 
測試分片............. .................................................. .............................................. 94 
端到端測試................................................. .................................................. ............ 102 
測試分佈式系統................................. .................................................. ............. 102 
消費者驅動的契約測試.............................. .................................................. ..... 104
Spring Cloud Contract ............................................... ........................................ 105 
總結........ .................................................. .................................................. .............. 113 

第5章遷移遺留的應用程序........................... ...................... 115 
契約.......................... .................................................. .............................................. 115 
遷移應用程序環境................................................. .................................................. . 116 
開箱即用的構建包(Buildpacks) ...................................... ............................... 116 
自定義的構建包............. .................................................. ................................. 117
容器化的應用程序............................................. ............................................... 118 
將應用程序遷移到雲上的微重構......................................... ..................................... 119 
連接後端服務........ .................................................. .......................................... 120 
用Spring實現服務平等.. .................................................. ................................ 121 
總結................ .................................................. .................................................. ...... 133 
第Ⅱ部分Web服務

第6章REST API................................. .......................... 137 
倫納德·理查森的成熟模型............... .................................................. ..................... 137
使用Spring MVC實現簡單的REST API .......................................... ....................... 139 
內容協商........................ .................................................. ......................................... 142 
xii |目錄
讀寫二進制數據. .................................................. ............................................. 142 
Google Protocol Buffers . .................................................. ................................. 145 
錯誤處理.............. .................................................. .................................................. . 150 
超媒體.............................................. .................................................. ....................... 152
媒體類型和模式.............................................. .................................................. 158 
API版本............................................... .................................................. .................. 159 
編寫REST API文檔........................... .................................................. .................... 162 
客戶端........................... .................................................. .......................................... 167 
用於臨時瀏覽和交互的REST客戶端............................................... ................ 167 
RestTemplate ................................ .................................................. ................... 171
總結................................................. .................................................. ....................... 177 

第7章路由...................... .............................................. 179 
DiscoveryClient接口. .................................................. ............................................. 180 
Cloud Foundry Route服務.................................................. ...................................... 190 
總結.......... .................................................. .................................................. ............ 195 

第8章邊緣服務................................ ............................... 197
Greetings服務................................................ .................................................. ........ 198 
一個簡單的邊緣服務.................................... .................................................. .......... 200 
Netflix Feign ..................................... .................................................. ...................... 202 
使用Netflix Zuul進行過濾和代理.................... .................................................. ..... 204 
自定義Zuul過濾器....................................... .................................................. .. 214 
邊緣服務的安全........................................... .................................................. ........... 218
OAuth ................................................. .................................................. .................... 219 
服務端應用程序......................... .................................................. ..................... 220 
HTML5和JavaScript單頁面應用程序..................... ........................................ 221 
沒有用戶的應用..... .................................................. ......................................... 221 
受信任的客戶端... .................................................. ........................................... 221 
Spring Security .... .................................................. .................................................. .. 222
Spring Cloud Security ............................................... ................................................ 227 
一個Spring Security OAuth授權服務器............................................. .............. 227 
保護Greetings資源服務器的安全............................. ....................................... 232 
創建一個受OAuth保護的單頁面應用程序.................................................. .... 238 
總結............................................ .................................................. ............................ 247 
目錄| xiii 

第Ⅲ部分數據整合
第9章數據管理........ .................................................. ..... 251 
數據建模......................................... .................................................. ........................ 251
關係數據庫管理系統(RDBMS) ........................................... ........................... 252 
NoSQL..................... .................................................. ........................................ 253 
Spring Data ....... .................................................. .................................................. .... 253 
Spring Data應用程序的結構....................................... ...................................... 254 
域類......... .................................................. .................................................. ...... 254 
庫.......................................... .................................................. .......................... 254
為領域數據組織Java包............................................ ........................................ 255 
使用JDBC訪問RDBMS數據.... .................................................. ........................... 258 
Spring的JDBC支持.................. .................................................. ............................ 259 
Spring Data示例.................. .................................................. ................................... 261 
Spring Data JPA........... .................................................. ............................................ 264 
Account Service ... .................................................. ............................................ 264
集成測試................................................ .................................................. ......... 274 
Spring Data MongoDB ..................................... .................................................. ....... 275 
Order Service ........................................ .................................................. ........... 275 
集成測試.................................... .................................................. ..................... 282 
Spring Data Neo4j ......................... .................................................. .......................... 284 
Inventory Service ..................... .................................................. ........................ 284
集成測試................................................ .................................................. ......... 294 
Spring Data Redis ..................................... .................................................. ............... 297 
高速緩存................................ .................................................. ......................... 298 
總結....................... .................................................. ................................................. 302 

第10章消息系統............................................. ................ 303 
Spring Integration的事件驅動架構........................... ................................................ 304
消息端點................................................ .................................................. ......... 305 
使用簡單的組件構建複雜的系統................................ ...................................... 306 
消息代理、橋接、競爭消費者模式和事件溯源................................................. ...... 314 
發布—訂閱目的地...................................... .................................................. .... 314 
點對點目的地.......................................... .................................................. ........ 315 
xiv |目錄
Spring Cloud Stream ................................... .................................................. ............ 315 
流生產者.................................. .................................................. ....................... 316
流消費者............................................... .................................................. .......... 321 
總結...................................... .................................................. .................................. 323 

第11章批處理和任務........ ................................................ 325 
批處理工作................................................ .................................................. ............. 325 
Spring Batch .................................. .................................................. .......................... 326 
我們的第一個批處理作業............... .................................................. ................ 327
調度................................................. .................................................. ....................... 336 
通過消息傳遞遠程分區Spring批處理作業................. ............................................. 337 
任務管理.. .................................................. .................................................. ............. 346 
通過Workflow進行的以工作流為中心的整合......................... ................................ 348 
使用消息傳遞的分佈式........... .................................................. ................................ 362 
總結................ .................................................. .................................................. ...... 362 

第12章數據集成...................................... ....................... 363
分佈式事務............................................... .................................................. .............. 364 
故障隔離和優雅的降級............................. .................................................. .............. 364 
saga模式................................. .................................................. ................................ 369 
CQRS(命令查詢責任分離) .......... .................................................. ........................ 369 
投訴API ....................... .................................................. ................................... 371 
投訴統計API ........... .................................................. ....................................... 383
Spring Cloud Data Flow .............................................. .............................................. 385 
Stream .. .................................................. .................................................. ......... 387 
任務....................................... .................................................. .......................... 390 
REST API ..................... .................................................. ................................... 391 
實現Data Flow客戶端......... .................................................. ........................... 392 
總結..................... .................................................. .................................................. . 407 
第IV部分生產
第13章可觀測的系統........................................... ............ 411 
你構建,你運行................................ .................................................. ...................... 412 
目錄| xv 
謀殺神秘微服務.................... .................................................. .................................. 413 
十二要素運維.......... .................................................. ............................................... 413 
新方式.................................................. .................................................. ................... 414 
可觀測性........................... .................................................. ...................................... 416
推與拉的可觀測性和解析率........................................ ............................................. 416 
使用Spring Boot Actuator捕獲應用程序的當前狀態............................................ ... 417 
度量............................................. .................................................. ........................... 418 
通過/info端點識別服務................ .................................................. ......................... 431 
健康檢查...................... .................................................. ........................................... 432 
審計事件.... .................................................. .................................................. ........... 436
應用程序日誌............................................... .................................................. .......... 439 
指定日誌輸出.................................... .................................................. .............. 440 
指定日誌級別................................ .................................................. .................. 441 
分佈式跟踪............................ .................................................. ................................. 445 
用Spring Cloud Sleuth尋找線索.......... .................................................. .......... 446 
多少數據是足夠的.................................. .................................................. ........ 447 
OpenZipkin :一張圖片勝過千絲萬縷.............................. ................................. 448
跟踪其他平台和技術............................................. ............................................ 454 
儀表板... .................................................. .................................................. ................ 455 
使用Hystrix儀表板監控下游服務.......................... .......................................... 455 
Codecentric的Spring Boot Admin .. .................................................. ................ 459 
Ordina Microservices儀表板............................. ................................................ 462 
Pivotal Cloud Foundry的AppsManager .............................................. .............. 463 
修復.................................. .................................................. ...................................... 465
總結................................................. .................................................. ....................... 467 
第14章服務代理..................... ........................................469 
創建後台服務...... .................................................. .................................................. . 470 
平台視圖.............................................. .................................................. ................... 472 
使用Spring Cloud Cloud Foundry Service Broker實現服務代理.................... ........... 473 
簡單的Amazon S3服務代理................................ ............................................ 473 
服務目錄... .................................................. .................................................. .... 474
管理服務實例............................................... .................................................. ... 476 
服務綁定........................................... .................................................. .............. 482 
保護服務代理................................ .................................................. .................. 486 
xvi |目錄
部署........................... .................................................. ............................................. 487 
使用BOSH發布. .................................................. ............................................ 487 
使用Cloud Foundry發布. .................................................. ............................... 488
註冊Amazon S3 Service Broker ............................................. .................................. 489 
創建Amazon S3服務實例.......... .................................................. ............................ 490 
消費服務實例.................. .................................................. ................................ 491 
S3客戶端應用程序............ .................................................. ..................................... 493 
運行測試.......... .................................................. .................................................. ..... 496 
總結........................................... .................................................. ............................. 496

第15章持續交付............................................. ................497 
持續集成之外............................. .................................................. ............................ 497 
John Allspaw在Flickr以及後來的Etsy ............. .............................................. 498 
Netflix的Adrian Cockroft ................................................. ............................... 499 
亞馬遜的持續交付.............. .................................................. ............................ 500 
流水線.................... .................................................. ................................................. 500 
測試................................................. .................................................. ....................... 501
持續交付微服務.............................................. .................................................. ........ 502 
工具........................................ .................................................. ................................ 503 
Concourse ................ .................................................. ............................................... 503 
容器. .................................................. .................................................. .............. 504 
持續交付微服務............................... .................................................. ....................... 504 
安裝Concourse ........................ .................................................. ....................... 505
基本的管道設計.............................................. .................................................. 506 
持續集成............................................... .................................................. .......... 518 
消費者驅動的協約測試................................. .................................................. .......... 518 
User微服務流水線................................... .................................................. ....... 519 
數據......................................... .................................................. ............................... 522 
生產................. .................................................. .................................................. ..... 523 
第V部分附錄
附錄A在Java EE中使用Spring Boot................................527 
索引....... .................................................. ...................... 552