Spring Boot 一直是 Java 開發生態系裡市佔率最高的框架,許多企業都採用其開發自身服務。隨著開發典範的轉移,即便 Spring 提供完整方案,開發者往往對架構修改及服務管理的工作怯步,是否移轉上雲也有所疑慮。在這場分享裡,將會介紹由 Azure 提供的 Spring Cloud 解決方案,並從最簡單的一個 Spring Boot 應用開始,逐步導入微服務架構、連接 Azure DB、藍綠部署到服務監控,讓開發者了解使用 Azure 運行 Spring 是一個簡單又有效率的體驗,加速將 JVM 應用上雲。
1. 簡化 JVM 上雲
范聖佑 (Shengyou Fan)
微軟最有價值專家
IT EXPLAINED 數位轉型攻略 IV
透過 Azure Spring Cloud
提升開發、發佈
及服務監控效率
2. 本⽇⼤綱
• 回顧 JVM ⽣態系及上雲痛點
• Azure Spring Cloud 簡介
• ⽰範開發 Spring Boot 應⽤並部署⾄ Azure Spring Cloud
• 實作回顧及延伸討論
• 學習資源
3. Spring - 最受歡迎的 Java 框架
Source: State of Spring 2020 Report - https://tanzu.vmware.com/content/ebooks/state-of-spring-2020
的開發者使⽤ Spring Boot 做為他們唯
⼀或主要的開發平台
52%
顯著的年增成長及採⽤率
4. 開發 Spring 應⽤的常⾒挑戰
管理 Spring Boot 應⽤的雲基
礎設施需要龐⼤的管理成本
難以管理應⽤程式的⽣命週期
為應⽤程式做故障排除很痛苦
Spring
Cloud Apps
Spring Cloud
Components
Spring Cloud
Components
Cloud
Services
App
Consumers
Breaker
dashboard
Service
registry
Distributed
tracing
Config
dashboard
IoT
Mobile
Browser
API
Gateway
Microservices
Microservices
Microservices
Message brokers
Databases
開發團隊需要⾃⾏管理基礎架構、更新和故障排除
7. Spring 與 Azure 的各項整合
App Configuration
Event Hubs
Service Bus
Storage
Redis
Functions
Spring Cloud
SQL Database
MySQL
PostgreSQL
Maria DB
Cosmos DB
• SQL
• MongoDB
• Cassandra
Spring Data
Active Directory (AAD)
AAD B2C
Spring Security
SQL Database
PostgreSQL
MySQL
R2DBC
Spring Cache
Redis Cache
Storage
Spring Resource
Spring Messaging
Service Bus
Micrometer
Monitor
只需幾⾏設定和少量的程式碼變更,Spring 開發者就可以連接到 30 多個 Azure 服務
8. 強⼤的夥伴⽣態
Solution templates for
WebLogic on Azure IaaS
Confluent Cloud with Azure
Portal and CLI integration
Jointly built and operated
service—Azure Spring Cloud
Redis Enterprise on Azure
managed infrastructure
Solution templates for
WebSphere on Azure IaaS
Jointly supported JBoss EAP
on App Service and VMs
Elastic Cloud on Azure
Marketplace
9. Demo 1:建立 Spring Boot 應⽤程式
• ⼯具
- IntelliJ IDEA
- Azure Toolkit for IntelliJ
- Azure CLI
- Azure Spring Cloud extension for Azure CLI
• 步驟
- 使⽤ IntelliJ IDEA 建立 Spring Boot 專案
- 使⽤ Docker Compose 建立開發⽤ MySQL
- 本機測試
10. Demo 2:部署⾄ Azure Spring Cloud
• Azure 設定
- 建立 Azure Database for MySQL servers
- 建立 Azure Spring Cloud
- 建立 App
• 步驟
- 使⽤ Gradle 建立 (Fat) Jar 檔
- 使⽤ IntelliJ IDEA 或 Azure CLI 部署
- 取得測試位址
11. Demo 3:建立 Spring Cloud Config server
• 步驟
- 建立 Spring Cloud Config Repository
- Push ⾄ Git Repository
- 設定 Azure Spring Cloud Config Server 的 Repository
位置
12. Demo 4:導入微服務架構
• 步驟
- 在 Spring Boot 應⽤程式增加相依套件
- 修改程式碼讀取 Config Server 上的 Value
- 部署更新
13. Demo 5:建立 Spring Cloud Gateway
• Azure 設定
- 建立 App 並開啟 Public Access
• 步驟
- 建立全新 Spring Cloud Gateway 應⽤程式
- 設定 Application Configuration
- 使⽤ Gradle 建立 (Fat) Jar 檔
- 使⽤ IntelliJ IDEA 或 Azure CLI 部署