【springCloud基础篇-12】Spring Cloud Config 配置中心之高可用

接上篇文章:https://mp.csdn.net/postedit/103089572

demo代码地址:https://download.csdn.net/download/qq_33333654/12014918

所谓高可用也是保证客户端调用服务端的时候能正常调用。解决方案就是服务端做成集群方式。

首先修改server项目

启动类添加注解: @EnableDiscoveryClient

 

接下来就是把服务端做成多个项目进行注册中心注册。这里我简单粗暴一点,复制项目文件夹,文件夹名称修改为:spring-cloud-config-server22

 

IDEA打卡该server22项目。

修改application.yml配置文件:

server:
  port: 9022
eureka:
  client:
    service-url:
      defaultZone: http://peer1:8000/eureka/,http://peer2:8001/eureka/,http://peer3:8002/eureka/
spring:
  application:
    name: spring-cloud-config-server
  profiles:
    active: native


 

 修改native-mysql.properties文件内容:

native.hello=hello_i_im_mysql_update

分别启动server项目与server22项目,打开注册中心,查看:

注册中心配置成功。

接下来就是修改客户端项目。

首先client项目启动类添加注解:@EnableDiscoveryClient

修改application.yml文件:

server:
  port: 9021
spring:
  application:
    name: spring-cloud-config-client
management:
  security:
    enabled: false #springboot 1.5.X以上默认开通了安全认证

 

注意这里没有了注册中心的配置。

修改bootstrap.yml文件:

spring:
  cloud:
    config:
      discovery:
        enabled: true
        serviceId: spring-cloud-config-server   #      uri: http://localhost:9020/
      name: native
      profile: mysql
      lable: master
eureka:
  client:
    service-url:
      defaultZone: http://peer1:8000/eureka/,http://peer2:8001/eureka/,http://peer3:8002/eureka/

注册中心迁移到这里来了,特别注意,删除了uri,修改为了

discovery:

      enabled: true

     serviceId: spring-cloud-config-server

这个非常重要。

接下来启动client项目。

访问:http://localhost:9021/hello

返回的是

native.hello=hello_i_im_mysql_update

然后我们手动将server项目关闭。

打开cmd命令窗口,执行:curl -X POST http://localhost:9021/refresh

已经刷新了配置文件,然后再次访问 http://localhost:9021/hello

OK完成

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不能吃辣的JAVA程序猿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值