微服务越来越受欢迎,每个月都有更多的库包和解决方案来支持微服务的开发测试,很多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平台为你准备了现成的微服务解决方案,并可以立即开始开发函数式微服务。
Java-Based Microservices Architecture and Abixen -