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、添加依赖

    

  1. <dependency>
  2. <groupId>org.springframework.cloud</groupId>
  3. <artifactId>spring-cloud-config-server</artifactId>
  4. </dependency>

  b、配置文件增加了eureka注册中心的配置

  1. spring.application.name=spring-cloud-config-server
  2. server.port=8001
  3. #读取本地文件
  4. spring.profiles.active=native
  5.  
  6. eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/

  c、启动类

  1. @EnableDiscoveryClient
  2. @EnableConfigServer //激活对配置中心的支持
  3. @SpringBootApplication
  4. public class ConfigServerApplication {
  5.  
  6. public static void main(String[] args) {
  7. SpringApplication.run(ConfigServerApplication.class, args);
  8. }
  9.  
  10. }

3、客户端修改,spring-cloud-houge-provider

  a、添加依赖

  1. <dependency>
  2. <groupId>org.springframework.cloud</groupId>
  3. <artifactId>spring-cloud-starter-config</artifactId>
  4. </dependency>

  b、application.properties

  

  1. spring.application.name=spring-cloud-provider
  2. server.port=9000
  3.  
  4. management.security.enabled=false

  c、bootstrap.properties

  1. spring.cloud.config.name=config
  2. spring.cloud.config.profile=dev
  3. #spring.cloud.config.uri=http://localhost:8001/
  4. #开启Config服务发现支持
  5. spring.cloud.config.discovery.enabled=true
  6. #指定server端的name,也就是server端spring.application.name的值
  7. spring.cloud.config.discovery.serviceId=spring-cloud-config-server
  8. #注册中心
  9. eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/

  d、启动类

  

  1. @SpringBootApplication
  2. @EnableDiscoveryClient //使项目有服务注册功能
  3. public class ProviderApplication {
  4.  
  5. public static void main(String[] args) {
  6. SpringApplication.run(ProviderApplication.class, args);
  7. }
  8. }

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. C# 文件/文件夹压缩解压缩

    项目上用到的,随手做个记录,哈哈. 直接上代码: using System; using System.Data; using System.Configuration; using System.C ...

  2. Intellij IDEA 最新旗舰版注册激活破解(2018亲测,可用)

    1.2017年亲测 参考:https://www.haxotron.com/jetbrains-intellij-idea-crack-123/ 安装IntelliJ IDEA 最新版 启动Intel ...

  3. BOM&DOM

    BOM(浏览器对象模型) 1. location相关 . location.href 获取当前url . location.href="http://www.sogo.com" 跳 ...

  4. PAT 1081 Rational Sum

    1081 Rational Sum (20 分)   Given N rational numbers in the form numerator/denominator, you are suppo ...

  5. SpringCloud服务负载均衡实现原理01

  6. Win10下安装zio

    0x00 报错:capstone.dll缺失,就算用pip安装也不行. 推荐:kali下安装pwn,pwntools,zio

  7. 微服务-注册与发现-zookeeper bydasn

    目录 一.微服务注册的概述 二.zookeeper2.1 zookeeper安装启动2.2 zookeeper集群搭建2.3 zkcli操作 一.微服务注册概述 在微服务中,有这么一个东西叫服务注册表 ...

  8. 使用Git上传项目到Gitee

    参考原文链接为:https://blog.csdn.net/qq944639839/article/details/79864081 1.打开GitBash 2. cd Client //进入工程目录 ...

  9. vm虚拟机下ubuntu连接上ssr

    第一步: 第二步: 第三步: 第四步: 完成!

  10. CentOS7 cannot find a valid baseurl for repo base

    找到文件夹: cd /etc/sysconfig/network-scripts/ 然后找ifcfg 开头的文件,挨个打开 里面有下面那些代码前三行的就是,添加后面DNS两行,保持并退出,然后继续执行 ...