前言
上一章节,简单介绍了分布式配置中心
Spring Cloud Config的使用。同时,我们也遗漏了一些问题,比如如何配置实时生效,当服务端地址变更或者集群部署时,如何指定服务端地址?回想,在服务注册章节,服务提供者和服务消费者,同时往注册中心进行注册和获取服务地址,而本身注册中心又支持高可用配置。所以,对于配置中心,我们也可以将Server端和Client端往注册中心进行注册,借此实现配置中心的服务化,无需指定具体的ip地址,直接根据服务名称进行调用。
其次,对于使用了
git或者svn作为存储方式时,本身配置仓库的高可用也是一个需要考虑的事项。本身如github或者码云这些第三方git仓库而言,已经实现了高可用了。但一般上部署的微服务都是内网服务,所以一般上是使用如gitlab开源的git仓库管理系统进行自建,此时就需要考虑本身仓库的高可用了。注意:本身教程为了不混淆各知识点,所以都是独立项目进行实例,而不是在原工程上进行修改。
本章节教程采用了多模块工程进行构建实例。父类项目名为:spring-cloud-config-ha。同时创建服务化的配置文件:my-config-client-ha-dev.properties和my-config-client-ha-test.propertiesmy-config-client-ha-dev.propertiesconfig=this is dev!my-config-client-ha-dev.propertiesconfig=this is test!Server端
创建子工程:
spring-cloud-confg-ha-server
0.加入pom依赖。<!-- config server 依赖 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency> <!-- 客户端依赖 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency>1.配置文件加入注册中心相关配置。
spring.application.name=spring-cloud-config-ha-server server.port=15678 #配置文件git配置 spring.cloud.config.server.git.uri=https://github.com/xie19900123/spring-cloud-learning.git # 搜索路
