微服务深入浅出(8)-- 配置中心Spring Cloud Config
Config Server从本地读取配置文件
将所有的配置文件统一写带Config Server过程的目录下,Config Server暴露Http API接口,Config Client调用Config Server的Http API来读取配置文件
1、引入依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
2、启动类添加@EnableConfigServer注解
@EnableConfigServer
@SpringBootApplication
public class DemoApplication { public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
3、工程配置文件配置本地读取
spring:
cloud:
config:
server:
native:
search-locations: classpath:/shared
profiles:
active: native
application:
name: config-server
server:
port: 9001
4、创建共享配置文件config-client-dev.yml
server:
port: 9002
foo: foo version 1
==========================
1、引入依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
2、bootstrap.yml作为程序的配置文件(bootstrap相对于application具有优先的执行顺序)
spring:
application:
name: config-client
cloud:
config:
uri: http://localhost:9001
fail-fast: true
profiles:
active: dev
这样的客户端程序已经在9002端口启动,也可以像本地文件一样读取远程的配置文件:
@Value("${foo}")
String foo;
@GetMapping("/hi")
public String hi() {
return foo;
}
Config Server从远程Git读取配置文件
spring:
cloud:
config:
server:
git:
uri: https://github.com/forezp/springcloudConfig
search-paths: respo
username: aaa
password: aaa
label: master
application:
name: config-server
高可用Config Server集群
1、配置Eureka Server
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
server:
port: 9003
eureka:
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://localhost:${server.port}/eureka
@EnableEurekaServer
@SpringBootApplication
public class DemoApplication { public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
2、改造config-server
spring:
cloud:
config:
server:
native:
search-locations: classpath:/shared
profiles:
active: native
application:
name: config-server
server:
port: 9001
eureka:
client:
service-url:
defaultZone: http://localhost:9003/eureka
@EnableConfigServer
@SpringBootApplication
@EnableEurekaClient
public class DemoApplication { public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
3、改造config-client
spring:
application:
name: config-client
cloud:
config:
fail-fast: true
discovery:
enabled: true
service-id: config-server
profiles:
active: dev
server:
port: 9002
eureka:
client:
service-url:
defaultZone: http://localhost:9003/eureka
@SpringBootApplication
@RestController
@EnableEurekaClient
public class DemoApplication { @Value("${foo}")
String foo; @GetMapping("/hi")
public String hi() {
return foo;
} public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
Spring Cloud Bus刷新配置
只需要改造config-client部分,消息驱动
1、引入依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
2、配置文件添加mq连接信息
spring:
application:
name: config-client
cloud:
config:
fail-fast: true
discovery:
enabled: true
service-id: config-server
profiles:
active: dev
rabbitmq:
host:
port:
username:
password:
management:
security:
enabled: false
3、在需要更新的配置类添加@RefreshScope,只有添加了该注解,才会服务不重启的情况下更新配置
4、访问一个应用,http://localhost:9003/bus/refresh即可更新所有集成了config-client的应用的配置信息
微服务深入浅出(8)-- 配置中心Spring Cloud Config的更多相关文章
- 第六篇: 分布式配置中心(Spring Cloud Config)
一.简介 在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件. 在Spring Cloud中,有分布式配置中心组件spring cloud confi ...
- Spring Cloud Config(一):聊聊分布式配置中心 Spring Cloud Config
目录 Spring Cloud Config(一):聊聊分布式配置中心 Spring Cloud Config Spring Cloud Config(二):基于Git搭建配置中心 Spring Cl ...
- 一起来学Spring Cloud | 第七章:分布式配置中心(Spring Cloud Config)
上一章节,我们讲解了服务网关zuul,本章节我们从git和本地两种存储配置信息的方式来讲解springcloud的分布式配置中心-Spring Cloud Config. 一.Spring Cloud ...
- 配置中心 Spring Cloud config
配置管理工具包,让你可以把配置放到远程服务器,集中化管理集群配置,目前支持本地存储.Git以及Subversion. 1.服务端 创建spring boot 项目 主要依赖 <dependenc ...
- SpringCloud(6)分布式配置中心Spring Cloud Config
1.Spring Cloud Config 简介 在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件.在Spring Cloud中,有分布式配置中心组 ...
- .NET Core微服务之基于Steeltoe使用Spring Cloud Config统一管理配置
Tip: 此篇已加入.NET Core微服务基础系列文章索引 => Steeltoe目录快速导航: 1. 基于Steeltoe使用Spring Cloud Eureka 2. 基于Steelt ...
- Spring Cloud(九)高可用的分布式配置中心 Spring Cloud Config 集成 Eureka 服务
上一篇文章,讲了SpringCloudConfig 集成Git仓库,这一篇我们讲一下SpringCloudConfig 配和 Eureka 注册中心一起使用 在分布式系统中,由于服务数量巨多,为了方便 ...
- springboot+cloud 学习(五)统一配置中心 spring cloud config + cloud bus + WebHooks +RibbitMQ
前言 微服务要实现集中管理微服务配置.不同环境不同配置.运行期间也可动态调整.配置修改后可以自动更新的需求,Spring Cloud Config同时满足了以上要求.Spring Cloud Conf ...
- 史上最简单的SpringCloud教程 | 第七篇: 高可用的分布式配置中心(Spring Cloud Config)
上一篇文章讲述了一个服务如何从配置中心读取文件,配置中心如何从远程git读取配置文件,当服务实例很多时,都从配置中心读取文件,这时可以考虑将配置中心做成一个微服务,将其集群化,从而达到高可用,架构图如 ...
随机推荐
- HDU 2103 Family planning
http://acm.hdu.edu.cn/showproblem.php?pid=2103 Problem Description As far as we known,there are so m ...
- 【Web Shell】- 技术剖析中国菜刀 - Part II
在第一部分,简单描述了中国菜刀的基本功能.本文我将剖析中国菜刀的平台多功能性.传输机制.交互模式和检测.我希望通过我的讲解,您能够根据您的环境检测出并清除它. 平台 那么中国菜刀可以在哪些平台上运行? ...
- SQL有三个类型的索引,唯一索引 不能有重复,但聚集索引,非聚集索引可以有重复
重要: (1) SQL如果创建时候,不指定类型那么默认是非聚集索引 (2) 聚集索引和非聚集索引都可以有重复记录,唯一索引不能有重复记录. (3) 主键 默认是加了唯一约束的聚集索引,但是也可以在主键 ...
- Memcache服务器端+Redis服务器端+PHP Memcache扩展+PHP Memcached扩展+PHP Redis扩展+MemAdmin Memcache管理工具+一些概念(更新中)
Memcache和Redis因为操作简单,是我们常用的服务器数据缓存系统,以下文字仅作备忘记录,部份转载至网络. 一.定义 1.Memcache Memcache是一个高性能的分布式的内存对象缓存系统 ...
- STM32标准外设库、 HAL库、LL库
工作以来一直使用ST的STM32系列芯片,ST为开发者提供了非常方便的开发库.到目前为止,有标准外设库(STD库).HAL库.LL库 三种.前两者都是常用的库,后面的LL库是ST最近才添加,目前支持的 ...
- FileZilla Server ftp 服务器下通过alias别名设置虚拟目录(多个分区)
最近检查服务器的时候发现磁盘空间不够用了,正好有两个硬盘正好,一个硬盘还空着,正好通过ftp服务器的别名功能实现添加空间了,这样就不用重新弄机器了 说明:FileZilla Server 的虚拟目录设 ...
- I Count Two Three HDU - 5878(暴力二分)
为甚么16年Qingdao Online 都是暴力题emm///... 先暴力预处理 然后lower _bound二分 #include <iostream> #include <c ...
- 【题解】CF#896 D-Nephren Runs a Cinema
容易发现这些 vip 用户并没什么用,所以考虑枚举手持50元与100元的人共有多少个.设手持50元的人 \(a\) 个,手持100元的人 \(a - k\) 个,那么一共是 \(2*a - k\) 个 ...
- 【刷题】BZOJ 3514 Codechef MARCH14 GERALD07加强版
Description N个点M条边的无向图,询问保留图中编号在[l,r]的边的时候图中的联通块个数. Input 第一行四个整数N.M.K.type,代表点数.边数.询问数以及询问是否加密. 接下来 ...
- Alpha 冲刺 —— 十分之四
队名 火箭少男100 组长博客 林燊大哥 作业博客 Alpha 冲鸭鸭鸭鸭! 成员冲刺阶段情况 林燊(组长) 过去两天完成了哪些任务 协调各成员之间的工作 协助前后端接口的开发 测试项目运行的服务器环 ...