0°

SpringCloud微服务技术解决方案

说起微服务现在真的是非常的火。那到底什么是微服务呢?说的简单一点,就是将原来的单一的服务拆分成多个微小的服务,这也是微服务名字的由来。那为什么要这么做呢?这么做有什么好处呢?


微服务架构的好处:

  • 易维护:现在公司在招聘时,职位是分的很细的。目的就是招专业的人做专业的事。当我们把服务拆分成了微服务,这样每个服务都可以让专业的人或者团队负责,而不需要了解整个系统的服务,这样比较方便熟悉业务,在出现问题时,也比较方便排查。
  • 健壮性:我们在开发项目时,通常会遇到各种各样的问题。但无论是哪一种问题,都可能对线上的服务产生影响。如果我们采用微服务的架构,那么即使是出问题,也是个别服务出问题,并不会对整个系统产生影响。最典型的例子就是2018年天猫双十一,收货地址服务虽然挂了,但丝毫不会影响我们买买买。
  • 跨语言:如我们上面介绍的微服务的本质就是将单一的服务拆分成多个微小的服务,每个服务与服务之间,通过某种技术使之通信。服务与服务之间完全独立。既然是相互独立的,那当然也就不限定语言了。也就是说,不同服务与服务之间可以采用不同的语言开发,只要保证它们彼此之间可以互相通信即可。

  上面是我们对微服务进行了简单的介绍。下面我们重点介绍一下本篇的重点内容SpringCloud的技术,并且我们来详细介绍一下为什么说SpringCloud是微服务技术的解决方案。在学习SpringCloud的技术之前,我们首先要掌握SpringBoot的技术。也就是本站最新更新的那几篇文章,如有不了解的欢迎留言。SpringCloud说白了就是帮助我们快速使用SpringBoot来创建微服务的。唯一不同之处,就是SpringCloud已经我们提供了很多的模块来帮助我们快速的进行微服务的开发。例如服务注册中心、配置中心、服务通信、服务网关、服务熔断等模块。全部的模块内容在SpringCloud的官方网站中有详细的介绍。地址为:

https://spring.io/projects/spring-cloud

  下面是摘取的SpringCloud官方网站内容,主要是有关SpringCloud核心模块的名字及其简介。

Main Projects

Spring Cloud Config

Centralized external configuration management backed by a git repository. The configuration resources map directly to Spring Environment but could be used by non-Spring applications if desired.
Spring Cloud Netflix

Integration with various Netflix OSS components (Eureka, Hystrix, Zuul, Archaius, etc.).
Spring Cloud Bus

An event bus for linking services and service instances together with distributed messaging. Useful for propagating state changes across a cluster (e.g. config change events).
Spring Cloud Cloudfoundry

Integrates your application with Pivotal Cloud Foundry. Provides a service discovery implementation and also makes it easy to implement SSO and OAuth2 protected resources.
Spring Cloud Open Service Broker

Provides a starting point for building a service broker that implements the Open Service Broker API.
Spring Cloud Cluster

Leadership election and common stateful patterns with an abstraction and implementation for Zookeeper, Redis, Hazelcast, Consul.
Spring Cloud Consul

Service discovery and configuration management with Hashicorp Consul.
Spring Cloud Security

Provides support for load-balanced OAuth2 rest client and authentication header relays in a Zuul proxy.
Spring Cloud Sleuth

Distributed tracing for Spring Cloud applications, compatible with Zipkin, HTrace and log-based (e.g. ELK) tracing.
Spring Cloud Data Flow

A cloud-native orchestration service for composable microservice applications on modern runtimes. Easy-to-use DSL, drag-and-drop GUI, and REST-APIs together simplifies the overall orchestration of microservice based data pipelines.
Spring Cloud Stream

A lightweight event-driven microservices framework to quickly build applications that can connect to external systems. Simple declarative model to send and receive messages using Apache Kafka or RabbitMQ between Spring Boot apps.
Spring Cloud Stream App Starters

Spring Cloud Stream App Starters are Spring Boot based Spring Integration applications that provide integration with external systems.
Spring Cloud Task

A short-lived microservices framework to quickly build applications that perform finite amounts of data processing. Simple declarative for adding both functional and non-functional features to Spring Boot apps.
Spring Cloud Task App Starters

Spring Cloud Task App Starters are Spring Boot applications that may be any process including Spring Batch jobs that do not run forever, and they end/stop after a finite period of data processing.
Spring Cloud Zookeeper

Service discovery and configuration management with Apache Zookeeper.
Spring Cloud AWS

Easy integration with hosted Amazon Web Services. It offers a convenient way to interact with AWS provided services using well-known Spring idioms and APIs, such as the messaging or caching API. Developers can build their application around the hosted services without having to care about infrastructure or maintenance.
Spring Cloud Connectors

Makes it easy for PaaS applications in a variety of platforms to connect to backend services like databases and message brokers (the project formerly known as "Spring Cloud").
Spring Cloud Starters

Spring Boot-style starter projects to ease dependency management for consumers of Spring Cloud. (Discontinued as a project and merged with the other projects after Angel.SR2.)
Spring Cloud CLI

Spring Boot CLI plugin for creating Spring Cloud component applications quickly in Groovy
Spring Cloud Contract

Spring Cloud Contract is an umbrella project holding solutions that help users in successfully implementing the Consumer Driven Contracts approach.
Spring Cloud Gateway

Spring Cloud Gateway is an intelligent and programmable router based on Project Reactor.
Spring Cloud OpenFeign

Spring Cloud OpenFeign provides integrations for Spring Boot apps through autoconfiguration and binding to the Spring Environment and other Spring programming model idioms.
Spring Cloud Pipelines

Spring Cloud Pipelines provides an opinionated deployment pipeline with steps to ensure that your application can be deployed in zero downtime fashion and easilly rolled back of something goes wrong.
Spring Cloud Function

Spring Cloud Function promotes the implementation of business logic via functions. It supports a uniform programming model across serverless providers, as well as the ability to run standalone (locally or in a PaaS).

  通过上面的一大篇的内容,我们知道SpringCloud里的内容核心模块非常非常的多,这时可能有人会比较担心,这么多的内容,我们要学习到啥时啊。我们不用有这样的顾虑,虽然都是核心的模块,但有的模块在我们的实际的开发中并不一定会用到,我们只要学习大部分微服务中常使用的模块即可。至于其它的模块,等我们在实际项目开发中用到在学习即可。除此之外,SpringCloud提供了这么多的模块,我们反而应该高兴,因为这些都是相对比较成熟的技术解决方案,可以满足我们开发微服务的各种需求。


  下面我们简单介绍一下SpringCloud中比较常见的模块,及其它们的作用。

  • 注册中心:既然是微服务了,那服务与与服务之间是怎么知道彼此的存在的呢,这时就需要注册中心这个功能了,只有它知道每个服务的具体地址。
  • 配置中心:因为微服务的技术架构,导致服务拆分的非常的多。所以这也就产生出了一个新问题,就是不同服务与服务之间相关的配置文件也非常的多。又因为正常的项目开发中,为了区分不同环境的服务, 常常也是通过配置文件来区分的。所以这么多的服务与这么多的配置文件如何有效的管理尤为的重要。所以怎么保证配置文件的统一管理非常的重要。所以SpringCloud提供了配置中心的模块来解决上述问题。
  • 服务通信:怎么保证服务与服务之间的调用是微服务的核心功能,SpringCloud中提供了3种服务调用的方式,我们将在稍后的文章中做详细的介绍。
  • 服务网关:在正常的项目开发中,为了保证项目的运行安全,服务与服务之间是不向外提供服务的,它们只是内部相互调用。当需要对外提供服务时,我们通常会通过SpringCloud为我们提供的网关的功能,根据请求的路径路由到相应的服务中。这样既保证了服务的运行安全,又比较方便的对请求进行权限验证。
  • 服务熔断:在采用微服务架构时,相关的服务也会部署多次,来保证满足负载的要求。不同服务与服务之间调用时,采用的是负载均衡的算法来选择一个最优的进行调用。那么如果某一个服务出线了问题怎么办呢?这时如果负载均衡选出来的最优的服务正好是坏的那个服务,那就会整个服务产生影响了。SpringCloud为了解决这样的问题,于是新增了服务熔断功能,可以对服务进行熔断或者对服务进行降级,这样就保证负载均衡选出来的服务基本是正常可以访问的服务。

  这就是本篇的全部内容,我们简单介绍了一下微服务的好处,及其SpringCloud中比较常见的模块。在接下来的文章中我们将按照上面介绍的内容来详细介绍一下注册中心、配置中心、服务通信、服务网关、服务熔断等方面的知识。谢谢。

教育
0 条回复 A 作者 M 管理员
    所有的伟大,都源于一个勇敢的开始!
欢迎您,新朋友,感谢参与互动!欢迎您 {{author}},您在本站有{{commentsCount}}条评论