美文网首页Spring Cloud 微服务架构学习
Spring Cloud构建微服务架构之配置中心

Spring Cloud构建微服务架构之配置中心

作者: SnowZhang | 来源:发表于2018-07-04 12:09 被阅读0次

    通过前面几篇文章的学习我们已经学会如何构建服务注册中心,服务发现与消费。本节我们介绍什么是spring cloud 配置中心,并学会如何使用spring-cloud-config 搭建一个分布式服务器的配置中心。

    什么是Spring Cloud Config

    spring官方对spring cloud config是这么定义的:

    Spring Cloud Config provides server and client-side support for externalized configuration in a distributed system. With the Config Server you have a central place to manage external properties for applications across all environments.

    大概的意思就是,Spring Cloud Config 将原本需要放在本地的配置文件,都几种配置到服务端了,也就是我们所说的配置中心。然后依赖这些配置的应用作为客户端,来动态的从配置中心读取配置。

    Spring Cloud Config工作流程

    Spring Cloud Config提供基于以下3个维度的配置管理:

    • 应用
      这个比较好理解,每个配置都是属于某一个应用的
    • 环境
      每个配置都是区分环境的,如dev, test, prod等
    • 版本
      这个可能是一般的配置中心所缺乏的,就是对同一份配置的不同版本管理,比如:可以通过Git进行版本控制。
      Spring Cloud Config提供版本的支持,也就是说对于一个应用的不同部署实例,可以从服务端获取到不同版本的配置,这对于一些特殊场景如:灰度发布,A/B测试等提供了很好的支持

    工作流程

    首先看下面的Spring Cloud Config 配置文件读取流程


    springcloudconfig.png

    上图简要描述了SpringCloudConfig的工作流程,图中主要包含四个元素

    • Config Client(Client abc)
      Client很好理解,就是使用了Spring Cloud Config的应用
      Spring Cloud Config提供了基于Spring的客户端,应用只要在代码中引入Spring Cloud Config Client的jar包即可工作
    • Config Server
      Config Server是需要独立部署的一个web应用,它负责把git上的配置返回给客户端
    • Remote Git Repository
      远程Git仓库,一般而言,我们会把配置放在一个远程仓库,通过现成的git客户端来管理配置
    • Local Git Repostiory
      Config Server的本地Git仓库
      Config Server接到来自客户端的配置获取请求后,会先把远程仓库的配置clone到本地的临时目录,然后从临时目录读取配置并返回。
      大致了解了Spring Cloud Config的工作原理,下一节我们将通过一个案例来体验Spring Cloud Config 的工作过程。

    相关文章

      网友评论

        本文标题:Spring Cloud构建微服务架构之配置中心

        本文链接:https://www.haomeiwen.com/subject/zjasuftx.html