配置中心微服务(Spring Cloud Config)

为什么需要配置服务中心?

1、统一维护
2、配置内容安全与权限

微服务之config server

注册到注册中心
启动类加注解:
@EnableConfigServer
@SpringCloudApplication
@EnableDiscoveryClient
/{name}-{profiles}.yml                <=======>    name 微服务名称 profiles 配置文件名
/{lable}/{name}-{profiles}.yml    <=======>   lable 分支 name 微服务名称 profiles 配置文件名

config client

cloud:
    config:
      name: ${spring.application.name},base,rabbitmq,eureka
      discovery:
        enabled: true
        service-id: config
      label: master
      fail-fast: true
    bus:
      refresh:
        enabled: true

微服务单元:如果没有注册到注册中心或者配置服务中心没有指定,会默认取localhost:8888的配置文件

服务开启:spring.cloud.config.discovery.enabled

DiscoveryClientConfigServiceBootstrapConfiguration

配置中心关键(服务发现配置类)

DiscoveryClientConfigServiceBootstrapConfiguration

2022-10-31 12:15:32.085 INFO   [7d5f039175af5088][7d5f039175af5088][] [io-30866-exec-7] c.c.c.ConfigServicePropertySourceLocator 87 : Fetching config from server at : http://ip:port/
2022-10-31 12:15:32.529 INFO   [7d5f039175af5088][7d5f039175af5088][] [io-30866-exec-7] c.c.c.ConfigServicePropertySourceLocator 87 : Located environment: name=base,redis,eureka,job,common, profiles=[dev], label=master, version=9a6d63f66ea87db71a7f737a093be73e228c35e1, state=null

git上的配置,与本地配置,dev环境时需要特别注意,服务发现配置项的调整!

手动刷新(/actuator/refresh,与SpringBoot版本有关)

curl -X POST "http://ip:port/actuator/refresh

自动刷新,利用SpringCloud Bus

引入RabbitMQ依赖,配置 

使用了配置项的Bean,类上加上注解@RefreshScope

配置webhook

便可以实现全自动刷新了!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值