微服務越來越受歡迎,每個月都有更多的庫包和解決方案來支持微服務的開發測試,很多Java開發人員雖然聽說過微服務,但是真正采用還是有猶豫的:“我知道,微服務是非常棒的,微服務器更容易維護和進一步開發,但我們沒有建立一個良好的基于??微服務架構的資源。”
許多嘗試創建微服務應用程序(例如使用Netflix OSS堆棧)的開發人員都疑惑他們是否有足夠的知識來配置整個系統。因為微服務架構所需知識與與單片monolithic 應用程序非常不同,需要額外的組件功能,如請求監視,用于在服務之間共享通信的隊列,注冊表服務,配置服務等等。同時為每個微服務保留一個單獨的數據模型也是一個很好的做法。
在創建模塊化Web應用程序時,開發人員必須專注于精心設計的業務領域設計。將模塊之間的所有耦合最小化,這樣至少避免了體系架構的復雜性。
Abixen Platform是一個完整的微服務架構系統,其源碼可見Github地址:https://github.com/abixen/abixen-platform,其體系組成部分如下:
1. Eureka:作為服務的注冊器。
2. Hystrix儀表板:允許我們實時監控請求狀態(例如,多少請求超時,多少次成功,多少次失敗等)。
3. Zipkin:一種分布式跟蹤系統,可幫助您收集應用程序中發生高延遲問題(性能慢)所需的數據。
4. Redis數據庫:用于保存登錄用戶的信息。
5. RabbitMQ:用作在特定微服務器之間發送消息的隊列。例如,核心微服務刪除一個模塊實例,需要讓商業智能微服務或Web內容微服務刪除與其相關的所有配置。
6. Abixen Platform Common:包含用函數式微服務實現的通用API的JAR。
7. Abixen平臺配置:配置微服務。整個應用程序可以在YAML文件中進行逐個配置。
8. Abixen Platform Web Client:核心功能的靜態內容,如頁面和模塊管理,安全管理等。
9. Abixen平臺網關:起到安全網關的作用。每個請求都必須通過這個微服務。
10. Abixen平臺核心:擁有自己的業務核心數據庫,擁有平臺的核心功能,如頁面和模塊管理,安全管理等。
11. Abixen平臺商業智能服務:由于應用程序帶來了函數性的微服務,因此我們將在這里放置一個用于商業智能報告,圖表創建和進一步管理的模塊。它也有自己的數據庫。
12. Abixen平臺Web內容服務:這與上述服務類似,但是這個函數可以提供內容創建功能,例如用戶可以創建文章。它還有自己的數據庫。
13. 您的服務:由開發人員使用該平臺創建的定制微服務。
該架構基于Netflix OSS技術棧。函數性的微服務不需要在整個平臺上都要部署,您如果不需要圖表或文章管理器,您也可以部署這個平臺并使用獨立開發的微服務。
該架構也很好地映射到Amazon組件。使用諸如EC2,ALB,ECS,ECR,Route53,CloudWatch,Elasticache,ERD和SES之類的服務在AWS上部署應用程序。
工作原理:
1. 用戶使用Web客戶端生成請求。通過Zuul Proxy,請求被轉發到網關微服務。
2. 網關微服務執行安全操作。如果用戶未通過身份驗證,則會引發“未經授權”的異常。如果經過身份驗證,則Zuul Proxy會決定將請求發送到核心平臺或指定的微服務,如商業智能,Web內容或由第三方開發人員創建的。
在下面的列表中,我們可以看到路由的示例配置:
zuul:
host:
connect-timeout-millis: 10000
socket-timeout-millis: 60000
routes:
# Begin of custom module microservices - add mapping relevant to your microservice
# Begin of Business Intelligence microservice
businessIntelligenceApplication:
path: /service/abixen/business-intelligence/application/**
url: http://business-intelligence-service:9091/service/abixen/business-intelligence/application
sensitive-headers:
businessIntelligenceApplicationApi:
path: /api/service/abixen/business-intelligence/application/**
url: http://business-intelligence-service:9091/api/service/abixen/business-intelligence/application
sensitive-headers:
businessIntelligenceAdmin:
path: /service/abixen/business-intelligence/control-panel/**
url: http://business-intelligence-service:9091/service/abixen/business-intelligence/control-panel
sensitive-headers:
businessIntelligenceAdminApi:
path: /api/service/abixen/business-intelligence/control-panel/**
url: http://business-intelligence-service:9091/api/service/abixen/business-intelligence/control-panel
sensitive-headers:
# End of Business Intelligence microservice
# Begin of Web Content microservice
webContentApplication:
path: /service/abixen/web-content/application/**
url: http://web-content-service:9092/service/abixen/web-content/application
sensitive-headers:
webContentApplicationApi:
path: /api/service/abixen/web-content/application/**
url: http://web-content-service:9092/api/service/abixen/web-content/application
sensitive-headers:
webContentAdmin:
path: /service/abixen/web-content/control-panel/**
url: http://web-content-service:9092/service/abixen/web-content/control-panel
sensitive-headers:
webContentAdminApi:
path: /api/service/abixen/web-content/control-panel/**
url: http://web-content-service:9092/api/service/abixen/web-content/control-panel
sensitive-headers:
# End of Web Content microservice
# End of custom module microservices
resource:
path: /resource/**
url: http://core:9000
sensitive-headers:
api:
path: /api/**
url: http://core:9000/api
sensitive-headers:
如何創建自己的微服務?
想要創建自己函數式微服務的開發人員可以使用通用API,有抽象接口,還必須包含部署描述符。該部署描述符文件描述了包含哪些模塊,什么可用的靜態資源,以及控制面板中是否有某種配置面板(控制面板是可配置的)。下面的列表是一個微服務器的部署描述符示例:
abixen:
platform:
adminSidebarItems:
-
name: data-source-sidebar-item
title: Data Sources
angularJsState: application.multiVisualisation.modules.databaseDataSource.list
orderIndex: 9
iconClass: fa fa-database
modules:
-
name: multi-visualisation
angularJsNameApplication: platformChartModule
angularJsNameAdmin: platformChartModule
title: Multi Visualisation
description: This is a multi visualisation module
relativeInitUrl: /service/abixen/business-intelligence/application/multi-visualisation/html/index.html
adminSidebarItems:
-
name: data-source-sidebar-item
staticResources:
-
relativeUrl: /service/abixen/business-intelligence/application/business-intelligence.min.css
resourcePageLocation: HEADER
resourcePage: APPLICATION
resourceType: CSS
-
relativeUrl: /service/abixen/business-intelligence/application/business-intelligence.min.js
resourcePageLocation: BODY
resourcePage: APPLICATION
resourceType: JAVASCRIPT
-
relativeUrl: /service/abixen/business-intelligence/application/lib/d3.min.js
resourcePageLocation: BODY
resourcePage: APPLICATION
resourceType: JAVASCRIPT
-
relativeUrl: /service/abixen/business-intelligence/application/lib/nv.d3.min.js
resourcePageLocation: BODY
resourcePage: APPLICATION
resourceType: JAVASCRIPT
-
relativeUrl: /service/abixen/business-intelligence/application/lib/nv.d3.min.css
resourcePageLocation: HEADER
resourcePage: APPLICATION
resourceType: CSS
-
relativeUrl: /service/abixen/business-intelligence/application/lib/angular-nvd3.min.js
resourcePageLocation: BODY
resourcePage: APPLICATION
resourceType: JAVASCRIPT
-
relativeUrl: /service/abixen/business-intelligence/control-panel/business-intelligence.min.css
resourcePageLocation: HEADER
resourcePage: ADMIN
resourceType: CSS
-
relativeUrl: /service/abixen/business-intelligence/control-panel/business-intelligence.min.js
resourcePageLocation: BODY
resourcePage: ADMIN
resourceType: JAVASCRIPT
我們可以看到,Java開發人員不必從頭開始創建整個微服務架構。Abixen平臺為你準備了現成的微服務解決方案,并可以立即開始開發函數式微服務。