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(六)配置中心服务化和高可用的更多相关文章

  1. springcloud(八):配置中心服务化和高可用

    在前两篇的介绍中,客户端都是直接调用配置中心的server端来获取配置文件信息.这样就存在了一个问题,客户端和服务端的耦合性太高,如果server端要做集群,客户端只能通过原始的方式来路由,serve ...

  2. Spring Cloud(八):分布式配置中心服务化和高可用

    在前两篇的介绍中,客户端都是直接调用配置中心的server端来获取配置文件信息.这样就存在了一个问题,客户端和服务端的耦合性太高,如果server端要做集群,客户端只能通过原始的方式来路由,serve ...

  3. spring cloud深入学习(九)-----配置中心服务化和高可用

    在前两篇的介绍中,客户端都是直接调用配置中心的server端来获取配置文件信息.这样就存在了一个问题,客户端和服务端的耦合性太高,如果server端要做集群,客户端只能通过原始的方式来路由,serve ...

  4. Spring Cloud(八):配置中心(服务化与高可用)【Finchley 版】

    Spring Cloud(八):配置中心(服务化与高可用)[Finchley 版]  发表于 2018-04-19 |  更新于 2018-04-26 |  本文接之前的<Spring Clou ...

  5. 七、springcloud之配置中心Config(二)之高可用集群

    方案一:传统作法(不推荐) 服务端负载均衡 将所有的Config Server都指向同一个Git仓库,这样所有的配置内容就通过统一的共享文件系统来维护,而客户端在指定Config Server位置时, ...

  6. Spring Cloud实战之初级入门(五)— 配置中心服务化与配置实时刷新

    目录 1.环境介绍 2.配置中心服务化 2.1 改造mirco-service-spring-config 2.2 改造mirco-service-provider.mirco-service-con ...

  7. SpringCloud 分布式配置中心

    SpringCloud 分布式配置中心 服务端 创建工程并完善结构 国际惯例,把maven工程创建完善 pom.xml <?xml version="1.0" encodin ...

  8. SpringCloud分布式配置中心Config

    统一管理所有配置. 1.微服务下的分布式配置中心 简介:讲解什么是配置中心及使用前后的好处 什么是配置中心: 一句话:统一管理配置, 快速切换各个环境的配置 相关产品: 百度的disconf 地址:h ...

  9. RabbitMQ高级指南:从配置、使用到高可用集群搭建

    本文大纲: 1. RabbitMQ简介 2. RabbitMQ安装与配置 3. C# 如何使用RabbitMQ 4. 几种Exchange模式 5. RPC 远程过程调用 6. RabbitMQ高可用 ...

随机推荐

  1. Token国内地铁使用城市

    天津 广州 深圳 南京 武汉 台北 高雄

  2. CentOS安装glibc异常Protected multilib versions

    安装失败 在执行yum install glibc.i686 libstdc++.i686 libcurl.i686安装命令时出现Protected multilib versions 解决方案 在命 ...

  3. 一个二维码如何自动识别是安卓(Android)还是苹果(IOS)

    思考问题: 通常,我们开发一个APP,有Android版本.IOS版本. 但是只有一个二维码?怎么办呢? 怎么让IOS用户扫描二维码下载IOS版本,Android用户扫描二维码下载到Android版本 ...

  4. 第5天(半天)【shell编程初步、grep及正则表达式】

    第5天(半天)[shell编程初步.grep及正则表达式] shell编程初步(01)_recv shell脚本:文本文件 #!:/bin/bash #!:/usr/bin/python #!:/us ...

  5. 1、安装Angular-CLI脚手架工具

    依赖环境的安装 1.安装node.js(版本在6以上) 查看版本号:node -v 2.安装npm(npm会随着node的安装一起被安装) 3.安装Python(我安装的是2.7.14),要安装环境变 ...

  6. 在Visual Studio 2017中安装bower

    在项目目录下添加一个文件.bowerrc { "directory": "wwwroot/lib" } JS包默认安装到webroot的lib文件夹,可以通过. ...

  7. js获取谷歌浏览器版本

    根据浏览器的useragent获取浏览器信息 // 获取谷歌浏览器版本 function getChromeVersion() { var arr = navigator.userAgent.spli ...

  8. Win10系列:C#应用控件基础15

    ProgressRing控件 上一小节讲解了ProgressBar控件的使用方法,ProgressRing控件和ProgressBar控件都是用来显示应用程序当前任务的运行进度信息,区别在于Progr ...

  9. DevExpress.Mvvm.Free

    DevExpress MVVM Framework is a set of components helping to work in the Model-View-ViewModel pattern ...

  10. xss之cookie窃取

    一.窃取cookie有什么用? cookie相当于一个身份证 有了管理员的cookie我们不需要帐号密码就可以登陆 二.反射型xss有存贮型xss什么区别? 反射 xss  和服务器没有交互 只能用一 ...