当前位置:网站首页>[microservices | Nacos] quickly realize the configuration center function of Nacos, and complete configuration update and version iteration
[microservices | Nacos] quickly realize the configuration center function of Nacos, and complete configuration update and version iteration
2022-06-22 03:04:00 【Bulst】
List of articles
Take on the last article , Let's continue our study nacos Another function of , Configuration center .
The new configuration
stay Nacos Spring Cloud in ,dataId The complete format is as follows :
${prefix}-${spring.profiles.active}.${file-extension}
- prefix The default is
spring.application.nameValue , You can also configurespring.cloud.nacos.config.prefixTo configure the . - spring.profiles.active That is, the current environment corresponds to profile, For details, please refer to Spring Boot file . Be careful : When spring.profiles.active It's empty time , Corresponding connector - There will be no ,dataId The splicing format of becomes
${prefix}.${file-extension} - file-exetension To configure the data format of the content , You can use the configuration item
spring.cloud.nacos.config.file-extensionTo configure the . Currently only supported properties and yaml type .
To configure @RefreshScope
adopt Spring Cloud Primary annotation @RefreshScope Implement automatic configuration update :
@RestController
@RequestMapping("/config")
@RefreshScope
public class ConfigController {
@Value("${useLocalCache:false}")
private boolean useLocalCache;
@RequestMapping("/get")
public boolean get() {
return useLocalCache;
}
}
Test code
Main code
@RefreshScope
@RequestMapping(value = "/producer")
@RestController
public class ProducerController {
@Value(value = "${server.port}")
private String port;
@Value("${ossa.info}")
private String config;
@GetMapping("/{id}")
// @SentinelResource(value = "producerById", fallback = "error")
public ResponseEntity<ProducerVO> producerById(@PathVariable(value = "id") String id) {
ProducerVO producerVO = new ProducerVO();
producerVO.setId(id);
producerVO.setPort(port + ": " + UUID.randomUUID().toString());
producerVO.setConfigBody(config);
return ResponseEntity.ok(producerVO);
}
spring:
application:
name: ossa-service-producer
cloud:
nacos:
# docker start-up 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: ip:8848
namespace: 78e10147-ff76-4e56-8b19-2e2bbd39f750
group: OSSA_GROUP
config:
server-addr: ip:8848
file-extension: yml
refresh-enabled: true
group: OSSA_GROUP
namespace: 78e10147-ff76-4e56-8b19-2e2bbd39f750
To configure nacos

Publish new configuration


test

边栏推荐
- C3-qt realize Gobang games (I) November 7, 2021
- tag动态规划-刷题预备知识-1.动态规划五部曲解题法 + lt.509. 斐波那契数/ 剑指Offer 10.I + lt.70. 爬楼梯彻底解惑 + 面试真题扩展
- The neo4j skill tree was officially released to help you easily master the neo4j map database
- 图数据平台解决方案:集群部署
- 交通标志分类
- Overview of web framework and program development
- [8. One dimensional prefix and]
- Redis6.0新特性(下)
- Classification of traffic signs
- 最热门海量的阿里云盘资源分享
猜你喜欢

The brand, products and services are working together. What will Dongfeng Nissan do next?

Implementation principle and application practice of Flink CDC mongodb connector

【Percona-Toolkit】系列之pt-table-checksum和pt-table-sync 数据校验修复神器

【爬虫笔记1】环境搭建和必要工具Selenium

PMP reference related agile knowledge

Force buckle 160 Intersecting linked list

360edr planing

libuv异步任务逻辑和uv_queue_work()

【4. 高精度加法】

C3-qt realize Gobang games (I) November 7, 2021
随机推荐
图像元数据(Metadata)获取与修改
图数据平台解决方案:单节点部署
Day20qt multiple forms switching idea 2021-10-31
Implementation principle and application practice of Flink CDC mongodb connector
Primary key in efcore
【论文】低光图像增强的零参考深度曲线估计
xpm_memory_tdpram原语的完整使用实例
torch.max()使用讲解
Write the processing framework for playing
ACL 2022 | multilingual knowledge map reasoning based on self supervised graph alignment
Li Kou today's question 1108 IP address invalidation
【leetcode周赛总结】LeetCode第298场周赛总结(6.19)
Sword finger offer 28 Symmetric binary tree
关于mysql的int型主键自增问题
Check information on the Internet after the college entrance examination, and pay attention to prevent websites without SSL certificates
table标签的不规则布局
Game jam development cycle
银联支付 返回商户 Nignx post请求405
C++ primer Chapter 2 summary of variables and basic types
Microsoft Internet Explorer was permanently closed on June 15