当前位置:网站首页>【微服务|Nacos】Nacos实现分布式配置中心进阶版
【微服务|Nacos】Nacos实现分布式配置中心进阶版
2022-06-21 16:49:00 【步尔斯特】
Spring Cloud Alibaba Nacos Config可支持自定义 Data Id 的配置。
完全关闭配置
通过设置 spring.cloud.nacos.config.enabled = false 来完全关闭 Spring Cloud Nacos Config
优先级
通过测试发现多个 Data Id 同时配置时,他的优先级关系是 spring.cloud.nacos.config.ext-config[n].data-id 其中 n 的值越大,优先级越高。
共享配置
# 共享文件
shared-configs[0]:
dataId: shared.yaml
# 自动刷新,默认不开启
refresh: true
shared-configs[1]:
dataId: shared1.yaml
refresh: true
扩展配置
# 扩展文件
extension-configs[0]:
dataId: extension.yaml
refresh: true
extension-configs[1]:
dataId: extension1.yaml
refresh: true
自动刷新
程序中如果写了@Value注解,可以采用@RefreshScope实现刷新,只需要在指定类上添加该注解即可
不同方式配置加载优先级:
Nacos 配置中心目前提供以下三种配置能力从 Nacos 拉取相关的配置,当三种方式共同使用时,他们的一个优先级关系是:A < B < C:
A:通过 spring.cloud.nacos.config.shared-configs[n].data-id 支持多个共享 Data Id 的配置
B:通过 spring.cloud.nacos.config.extension-configs[n].data-id 的方式支持多个扩展 Data Id 的配置
C:通过内部相关规则(spring.cloud.nacos.config.prefix、spring.cloud.nacos.config.file-extension、spring.cloud.nacos.config.group)自动生成相关的 Data Id 配置
bootstrap.yml
spring:
profiles:
active: dev
application:
name: ossa-service-producer
cloud:
nacos:
# docker启动nacos:
# docker run --name mynacos -itd -e MODE=standalone -p 8848:8848 -p 9848:9848 -p 9849:9849 nacos/nacos-server:v2.0.3
discovery:
server-addr: 1.117.66.67
# namespace: d5042bab-be48-4946-9465-fb6e15ab75b7
# group: OSSA_GROUP
config:
# 默认就是 服务名 + 环境名 + . + yaml
server-addr: 1.117.66.67
file-extension: yaml
refresh-enabled: true
# group: OSSA_GROUP
# namespace: d5042bab-be48-4946-9465-fb6e15ab75b7
# 共享文件
shared-configs[0]:
dataId: shared.yaml
# 自动刷新,默认不开启
refresh: true
shared-configs[1]:
dataId: shared1.yaml
refresh: true
# 扩展文件
extension-configs[0]:
dataId: extension.yaml
refresh: true
extension-configs[1]:
dataId: extension1.yaml
refresh: true
边栏推荐
- 在国元期货开户做期货安全吗?
- The way for programmers to learn
- Runmeide Healthcare a réussi l'audience d'inscription sur la liste: les pertes devraient augmenter, Huo Yunfei Brothers détenant environ 33%
- Let, with, apply, also, run
- C语言dll动态链接库
- solidity智能合约面试题
- Structural modeling and Design -- a practical summary of the functions of rotary cutting and fillet chamfering in feature forming of SolidWorks software (drawing a countersunk screw hole)
- EtherCAT igh主站控制3个台达asdaa2伺服转圈圈
- C language DLL Dynamic Link Library
- 性能测试---locust的on_start 和 on_stop 方法
猜你喜欢

2022年R1快开门式压力容器操作操作证考试题库模拟考试平台操作

信创环境下缓存服务Redis集群部署

C language DLL Dynamic Link Library

Simulation of vector

Not graduated from a first-class university, but passed the self-study software test and entered the initial 22K annual salary of Alibaba

主动学习(Active Learning) 概述、策略和不确定性度量

案例驱动 :从入门到掌握Shell编程详细指南

Byte Jump propose un nouveau type de réseau léger et efficace, mobovit, qui surpasse GhostNet et mobilenetv3 dans la classification, la détection et d'autres tâches CV!

C语言dll动态链接库

EtherCAT igh master station controls three Delta asdaa2 servo rotating circles
随机推荐
超分之RLSP
Stack awareness - stack overflow instance (ret2libc)
服务端socket程序
Post Gartner webinar "nine questions on digital transformation"
Tcpserver enable multithreading
Deeply understand the attention mechanism of map
National administrative division
Class, interface, function
字节流量生意经:变现趁早、缝钱袋子、All in卖货
Technical architecture of large websites | information encryption technology and key security management
Simulation Implementation of list
Byte Jump propose un nouveau type de réseau léger et efficace, mobovit, qui surpasse GhostNet et mobilenetv3 dans la classification, la détection et d'autres tâches CV!
Leetcode 1108 IP address invalidation [violence] the leetcode path of heroding
泰克示波器TCP202电流探头的使用说明
EtherCAT igh主站控制3个台达asdaa2伺服转圈圈
是关于Linux中一步建立yum源缓存问题
Redis6.0 new features (Part 1)
RT thread persimmon pie M7 Quanzhi f133 DDR running xboot
Reids面试题集合 数据结构+穿透雪崩+持久化+内存淘汰策略+数据库双写+哨兵
Application architecture principles