什么是微服务、微服务架构

本文基于微服务提出者马丁.福勒(Martin Fowler) 的微服务论文

一、什么是微服务

While there is no precise definition of this architectural style, there are certain common characteristics around organization around business capability, automated deployment, intelligence in the endpoints, and decentralized control of languages and data.
对于微服务,业界并没有一个统一的、明确的定义

简单的说,微服务是指将一个单体的应用程序拆分成一组小型服务;微服务化的核心就是将传统的一站式应用,根据业务拆分成一个一个的服务,彻底地去耦合,每一个微服务提供单个业务功能的服务,一个服务做一件事,从技术角度看就是一种小而独立的处理过程,类似进程概念,能够自行单独启动或销毁,拥有自己独立的数据库。

从狭义上看,每一个微型服务对应我们IDEA中构建的一个个Module

二、什么是微服务架构

In short, the microservice architectural style 1 is an approach to developing a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms, often an HTTP resource API. These services are built around business capabilities and independently deployable by fully automated deployment machinery.
总之,微服务架构风格是一种将一个单体应用拆分成一组小型服务的方法,每个服务运行在自己独立的进程中,并与轻量级的通信机制(通常是HTTP resource API)通信。这些服务是围绕业务能力进行构建的,可以通过完全自动化的机器进行部署。

  • 微服务架构即是基于微服务理念的架构风格(SpringCloud是分布式微服务架构下的一站式解决方案,是各个微服务架构落地技术的集合体,俗称微服务全家桶)

  • 单体应用到微服务的演进:

Enterprise Applications are often built in three main parts: a client-side user interface (consisting of HTML pages and javascript running in a browser on the user’s machine) a database (consisting of many tables inserted into a common, and usually relational, database management system), and a server-side application.
企业应用服务通常由这三个主要部分组成:客户端用户界面(由运行在用户机器的浏览器上的HTML页面和JS脚本组成)、数据库(通常由一种公共的关系型数据库管理系统的众多表组成)和服务端应用程序。

The server-side application will handle HTTP requests, execute domain logic, retrieve and update data from the database, and select and populate HTML views to be sent to the browser.
服务器端应用程序将处理HTTP请求,执行业务逻辑,从数据库检索和更新数据,并选择并填充要发送给浏览器的HTML视图。

This server-side application is a monolith - a single logical executable2.
这种服务器端应用程序是一个大型整体性的-一个逻辑单一的可执行文件。

这句是重点了:

Any changes to the system involve building and deploying a new version of the server-side application.
对系统的任何更改都涉及构建和部署一个新版本的服务器端应用程序。

随着时间的推移,系统变得越来越庞大且复杂,对系统的一小部分做出的更改都需要重建并部署整个系统,这使得开发和维护系统的成本变得高昂。
这些缺陷催生了微服务架构风格:将应用程序构建为微服务组件。这种微服务组件包括了这些特性:

  1. 服务是独立部署的和可独立扩展的;
  2. 服务有稳定的模块边界,甚至允许使用不同的语言来编写不同的服务;
  3. 不同的服务可以使用不同的数据库,可以由不同的团队来管理。

Martin Fowler的论文中有这样一张图片,很好的描述了单体应用和微服务的区别:
什么是微服务、微服务架构_第1张图片


  1. The term “microservice” was discussed at a workshop of software architects near Venice in May, 2011 to describe what the participants saw as a common architectural style that many of them had been recently exploring. In May 2012, the same group decided on “microservices” as the most appropriate name. James presented some of these ideas as a case study in March 2012 at 33rd Degree in Krakow in Microservices - Java, the Unix Way as did Fred George about the same time. Adrian Cockcroft at Netflix, describing this approach as “fine grained SOA” was pioneering the style at web scale as were many of the others mentioned in this article - Joe Walnes, Daniel Terhorst-North, Evan Botcher and Graham Tackley. ↩︎

  2. Unix社区使用Monolith一词已有一段时间了。它出现在The Art of Unix Programming来描述那些变得太大的系统 ↩︎

你可能感兴趣的:(微服务,java学习笔记)