二十、springcloud(六)配置中心服务化和高可用
1、问题描述
前一篇,spring-cloud-houge-provider(称之为客户端)直接从spring-cloud-houge-config(称之为服务端)读取配置,客户端和服务端的耦合性太高,服务端改变IP地址的时候,客户端也需要修改配置,不符合springcloud服务治理的理念。我们只需要将server端当做一个服务注册到eureka中,client端去eureka中去获取配置中心server端的服务既可。spring-cloud-houge-provider当提供接口服务时为server端,当读取属性文件时为client端,切莫混淆。
2、服务端修改,spring-cloud-houge-config
a、添加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
b、配置文件增加了eureka注册中心的配置
spring.application.name=spring-cloud-config-server
server.port=8001
#读取本地文件
spring.profiles.active=native eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/
c、启动类
@EnableDiscoveryClient
@EnableConfigServer //激活对配置中心的支持
@SpringBootApplication
public class ConfigServerApplication { public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
} }
3、客户端修改,spring-cloud-houge-provider
a、添加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
b、application.properties
spring.application.name=spring-cloud-provider
server.port=9000 management.security.enabled=false
c、bootstrap.properties
spring.cloud.config.name=config
spring.cloud.config.profile=dev
#spring.cloud.config.uri=http://localhost:8001/
#开启Config服务发现支持
spring.cloud.config.discovery.enabled=true
#指定server端的name,也就是server端spring.application.name的值
spring.cloud.config.discovery.serviceId=spring-cloud-config-server
#注册中心
eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/
d、启动类
@SpringBootApplication
@EnableDiscoveryClient //使项目有服务注册功能
public class ProviderApplication { public static void main(String[] args) {
SpringApplication.run(ProviderApplication.class, args);
}
}
4、启动服务
启动注册中心:http://localhost:8000/
启动config:http://localhost:8001/config-dev.properties
启动spring-cloud-houge-provider

http://localhost:9000/dynasty/hello?name=monkey

5、高可用
为了模拟生产集群环境,我们改动server端的端口为8003,再启动一个server端来做服务的负载,提供高可用的server端支持。防止某一台down掉之后影响整个系统的使用。代码重复,请自行测试
二十、springcloud(六)配置中心服务化和高可用的更多相关文章
- springcloud(八):配置中心服务化和高可用
在前两篇的介绍中,客户端都是直接调用配置中心的server端来获取配置文件信息.这样就存在了一个问题,客户端和服务端的耦合性太高,如果server端要做集群,客户端只能通过原始的方式来路由,serve ...
- Spring Cloud(八):分布式配置中心服务化和高可用
在前两篇的介绍中,客户端都是直接调用配置中心的server端来获取配置文件信息.这样就存在了一个问题,客户端和服务端的耦合性太高,如果server端要做集群,客户端只能通过原始的方式来路由,serve ...
- spring cloud深入学习(九)-----配置中心服务化和高可用
在前两篇的介绍中,客户端都是直接调用配置中心的server端来获取配置文件信息.这样就存在了一个问题,客户端和服务端的耦合性太高,如果server端要做集群,客户端只能通过原始的方式来路由,serve ...
- Spring Cloud(八):配置中心(服务化与高可用)【Finchley 版】
Spring Cloud(八):配置中心(服务化与高可用)[Finchley 版] 发表于 2018-04-19 | 更新于 2018-04-26 | 本文接之前的<Spring Clou ...
- 七、springcloud之配置中心Config(二)之高可用集群
方案一:传统作法(不推荐) 服务端负载均衡 将所有的Config Server都指向同一个Git仓库,这样所有的配置内容就通过统一的共享文件系统来维护,而客户端在指定Config Server位置时, ...
- Spring Cloud实战之初级入门(五)— 配置中心服务化与配置实时刷新
目录 1.环境介绍 2.配置中心服务化 2.1 改造mirco-service-spring-config 2.2 改造mirco-service-provider.mirco-service-con ...
- SpringCloud 分布式配置中心
SpringCloud 分布式配置中心 服务端 创建工程并完善结构 国际惯例,把maven工程创建完善 pom.xml <?xml version="1.0" encodin ...
- SpringCloud分布式配置中心Config
统一管理所有配置. 1.微服务下的分布式配置中心 简介:讲解什么是配置中心及使用前后的好处 什么是配置中心: 一句话:统一管理配置, 快速切换各个环境的配置 相关产品: 百度的disconf 地址:h ...
- RabbitMQ高级指南:从配置、使用到高可用集群搭建
本文大纲: 1. RabbitMQ简介 2. RabbitMQ安装与配置 3. C# 如何使用RabbitMQ 4. 几种Exchange模式 5. RPC 远程过程调用 6. RabbitMQ高可用 ...
随机推荐
- CentOS7.x系统中使用Docker时,在存储方面需要注意的问题
简述: 1.Docker 1.12.6/v17.03文档中CentOS7系统下安装时,明确说明,用于生产时,必须使用devicemapper驱动的direct-lvm模式,需要我们提前准备好块设备,以 ...
- linux中执行shell命令的几种常用方法
1 切换到shell脚本所在目录执行shell脚本: cd /test/shell ./test.sh 2 以绝对路径的方式执行shell脚本: /test/shell/test.sh 3 直接使用b ...
- 『流畅的Python』第12章:继承的优缺点
- Weka中数据挖掘与机器学习系列之Weka系统安装(四)
能来看我这篇博客的朋友,想必大家都知道,Weka采用Java编写的,因此,具有Java“一次编译,到处运行”的特性.支持的操作系统有Windows x86.Windows x64.Mac OS X.L ...
- Python—全局变量、局部变量、匿名函数
局部变量和全局变量 college1 = 'JMU' #全局变量 def change_name(name): college1 = 'LiGong' #局部变量,此函数是其作用域 # global ...
- c函数 文件名通配符
static bool IsMatched(CONST TCHAR* p, CONST TCHAR* q) { CONST TCHAR *r, *z, *x = _T(""); f ...
- shell脚本结构
echo $? 代表上一次命令的状态返回值,‘0’则代表为真<执行成功>,‘非零’则代表为假<执行失败>. shell脚本: <判断老男孩的年纪> [root@bo ...
- format格式化和函数
{[name][:][[fill]align][sign][#][0][width][,][.precision][type]}用{ }包裹name命名传递给format以命名=值 写法, 非字典映射 ...
- java数学函数Math类中常用的方法
Math类提供了常用的一些数学函数,如:三角函数.对数.指数等.一个数学公式如果想用代码表示,则可以将其拆分然后套用Math类下的方法即可. Math.abs(12.3); ...
- .NET并行计算和并发7-Task异步
使用任务并行库执行异步任务 下面的示例演示如何通过调用 TaskFactory.StartNew 方法来创建并使用 Task 对象. using System; using System.Thread ...