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. excel加密文件破解代码

    1. AIT+F11  2. 代码   3. F5 Public Sub AllInternalPasswords()' Breaks worksheet and workbook structure ...

  2. Js异常的处理

    博客1:  https://segmentfault.com/a/1190000011481099 express中的异常处理:https://blog.fundebug.com/2017/12/06 ...

  3. SQLLITE HELPER

    using System;using System.Data.SQLite; namespace SQLiteSamples{    class Program    {        //数据库连接 ...

  4. 微信小程序 自定义三列城市弹窗

    1.WXML <picker mode="multiSelector" bindchange="bindMultiPickerChange" bindco ...

  5. HTTP协议(二)之确保web安全的HTTPS

    一.概述 https并非是应用层的一种新协议.只是HTTP通信接口部分用SSL和TLS协议替代. 通常,HTTP直接和TCP通信.当使用SSL时,则演变成先和SSL通信,再由SSL和TCP通信了. 简 ...

  6. STL标准库-容器-deque 双端队列

    头文件: #include<deque> 常用操作: https://www.cnblogs.com/LearningTheLoad/p/7450948.html

  7. Matlab:Crank Nicolson方法求解线性抛物方程

    tic; clear clc M=[,,,,,,];%x的步数 K=M; %时间t的步数 :length(M) hx=/M(p); ht=/K(p); r=ht/hx^; %网格比 x=:hx:; t ...

  8. 【转载】基于webpack构建react项目

    第一部分链接:下载所需内容并构建基础的页面 第二部分链接:添加webpack中的一些常用babel和loader 第三部分链接:开发环境与生产环境的配置

  9. 颜色(color)透明

    颜色写法: 1.英文单词 backgroud-color:red: 2. #fff background-color:#fff; 3.#fefefe background-color:fefefe; ...

  10. String.valueOf() ,其他类型转为字符型

    1. 由 基本数据型态转换成 String String 类别中已经提供了将基本数据型态转换成 String 的 static 方法 也就是 String.valueOf() 这个参数多载的方法 有下 ...