Spring Cloud全解析:配置中心之解决configserver单点问题

解决configserver单点问题

之前我们在config的客户端配置configserver的地址是

 

yaml

代码解读

复制代码

spring: application: name: micro-service-config-client cloud: config: name: micro-service-config-client #github上的资源文件名,对应上述的application,该值默认为${spring.application.name}的值 profile: dev # 环境 label: master # git分支 uri: http://localhost:7010 #spring cloud 服务端地址

但是如果该configserver挂掉了,那就无法获取最新的配置了,微服务就出现了configserver的单点问题,那么如何避免configserver单点呢?

SpringCloudConfig早就想到了这个问题了,微服务可以使用注册中心来防止单点故障,那么configServer也是可以的

首先将configServer注册到eureka注册中心上

 

yaml

代码解读

复制代码

# eureka 配置 eureka: client: # 注册到eureka server注册中心 service-url: defaultZone: http://localhost:7001/eureka # eureka server提供的注册地址 instance: instance-id: springcloud2-springcloudconfig # 服务实例名称,在eureka server页面中的status列中 prefer-ip-address: true # 访问路径显示ip

然后在configClient端配置configServer地址的时候不使用uri的方式,而使用serviceId

 

yaml

代码解读

复制代码

spring: application: name: springcloud2-config-client cloud: config: name: springcloud2-config #github上的资源文件名 profile: dev # 环境 label: master # git分支 # uri: http://localhost:7010 #spring cloud 服务端地址 discovery: service-id: springcloud2-springcloudconfig # 可以使用eureka来访问到对应的configserver微服务,防止configserver单点问题 enabled: true

当然,configClient也要注册到注册中心上,不然是肯定找不到对应的configServer的

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值