APP下载

基于Spring Cloud和Docker的分布式微服务架构设计

2019-10-21黄强文曾丹

微型电脑应用 2019年6期

黄强文 曾丹

摘 要: 近年来,微服务架构是当前最流行的分布式系统类型之一,相比傳统单体架构它解决了数据、服务呈爆炸式增长带来的冲击问题。以构建一个天气预报分布式微服务系统为例,利用Spring Cloud框架将系统垂直切分为四个独立的业务服务:城市数据API微服务、天气数据采集微服务、天气数据API微服务和天气预报微服务。系统集成Eureka做服务发现,使用Zuul做路由网关,结合Hystrix熔断机制提高了系统的容错性,并使用Docker容器快速独立部署所有微服务,实现了开发、测试、部署运维的一体化。

关键词: 微服务架构; Spring Cloud框架; Docker容器

中图分类号: TP309

文献标志码: A

文章编号:1007-757X(2019)06-0098-04

Abstract: In recent years, as one of the most popular distributed system types, the microservice architecture has solved the problem of explosive growth of data and services compared to the traditional singleton architecture. Taking the construction of a weather forecast distributed microservice system as an example, this paper uses the Spring Cloud framework to divide the system vertically into four separate business services: the city data API microservice, the weather data collection microservice, the weather data API microservice, and the weather forecast microservice. The system integrates Eureka for service discovering, uses Zuul as a routing gateway, improves the fault tolerance of the system in conjunction with the Hystrix zapping mechanism, and uses the Docker container to quickly and independently deploy all services, it realizes the integration of development, tests, deployment operation and maintenance.

Key words: Microservice architecture; Spring Cloud framework; Docker container

0 引言

随着互联网、云计算的高速发展,人们对数据信息化服务依赖程度越来越深。以往的单体应用架构和面向服务化应用的架构逐渐不能满足业务的需求。而微服务这种分布式架构的兴起,是云计算应用快速发展的必然产物,也将是未来整个软件应用架构向着灵活多变、低耦合、高扩展性、动态伸缩发展的一个必然方向[1]。与此同时,Docker的诞生,代表着容器虚拟化技术的盛行高峰,它将极大减少微服务应用实现大规模部署、落地的成本。

微服务架构就是将单体应用拆分为多个高内聚低耦合的小型服务,每个小服务运行在独立进程,由不同的团队开发和维护,服务间采用轻量级通信机制,独立自动部署,可以采用不同的语言及存储。微服务架构具有如下优势[2]:

(1) 微服务架构将业务系统彻底的组件化、服务化,微服务专注于业务逻辑,服务功

登录APP查看全文