当前位置:网站首页>Actual combat of Nacos configuration center, standard components of Pangu microservice development
Actual combat of Nacos configuration center, standard components of Pangu microservice development
2022-06-09 11:31:00 【InfoQ】
Configuration center introduction
- Fast QA: In the previous article Nacos For service registration , Why is the configuration center the same ?
- Nacos Is to build in “ service ” Modern application architecture centered ( For example, the microservices paradigm 、 Cloud native paradigm ) Service infrastructure . Commit to discovering 、 Configure and manage microservices , It perfectly integrates the configuration center and the service registry . therefore ,Nacos It is not only a service registry, but also a fully functional distributed configuration center .
- Fast QA: Can the development mode of single layered architecture also be configured using the configuration center ?
- The configuration center is a strongly recommended mandatory standard component in the distributed microservice architecture development environment . But if you are developing on a single layered architecture , The configuration center can also be used . For these basic abilities , Whether it's a microservice or an individual , Pangu frames are perfectly fitted , Just rely on
pangu-spring-boot-starterYou can use it out of the box .
Explain the related terms
Namespace
Configuration Management
Configuration item
config set
config set ID
Configure snapshot
Compare the local configuration with the configuration center
- Local configuration ( The configuration file )
- The configuration is decentralized 、 Coupling with application 、 Static configuration
- No environment isolation, no version support , Easy to cause production accidents
- No safety audit
- Configuration center
- Configuration set 、 Externalization 、 Dynamic and effective in real time
- Multi environment isolation and multi version support , Safer
- Configure permission control 、 Operation change audit
Actual combat center configuration
Install relevant Pangu modules
- Pangu Parent
<parent>
<groupId>com.gitee.pulanos.pangu</groupId>
<artifactId>pangu-parent</artifactId>
<version>latest.version.xxx</version>
<relativePath/>
</parent>
- Basic module
<dependency>
<groupId>com.gitee.pulanos.pangu</groupId>
<artifactId>pangu-spring-boot-starter</artifactId>
</dependency>
Local configuration
spring.application.name=pangu-examples-config-remote-nacos
spring.profiles.active=${spring.profiles.active:dev}
nacos.config.bootstrap.enable=true
nacos.config.bootstrap.log-enable=true
nacos.config.auto-refresh=true
nacos.config.namespace=${nacos.namespace:pangu-dev}
nacos.config.server-addr=${nacos.server-addr:127.0.0.1:8848}
#nacos.config.type=yaml
nacos.config.type=properties
nacos.config.data-id=${spring.application.name}
Key configuration item description
- nacos.config.auto-refresh
- After the configuration of the configuration center is changed, it will be automatically refreshed to the configuration client
- nacos.config.namespace
- Namespace ( Note that it corresponds to the namespace ID value ), It is recommended to use namespaces to distinguish deployment environments
- nacos.config.server-addr
- Configure the communication address of the center
- nacos.config.type
- Configuration format used by configuration center ( properties、yaml etc. )
- nacos.config.data-id
- Unique identification of a configuration set in the configuration center
Configuration center configuration
- Fast QA: How the client works with Nacos Configure data synchronization in the center ?
- Client pass http Long polling mechanism pull nacos server The configuration data of the terminal , The configuration snapshot will be created locally ( disaster ). During the long polling timeout ,nacos server If the configuration of the terminal changes , Will actively write the configuration to response And back to , Simulated “ push ” effect . Therefore, the client can perceive the configuration changes of the configuration center in real time .
Create a namespace
pangu-dev
Create configuration set
pangu-examples-config-remote-nacos- Configuration set list

- newly added / Edit configuration set

Starting entrance
@SpringBootApplication
public class NacosConfigurationApplication {
public static void main(String[] args) {
PanGuApplicationBuilder.init(NacosConfigurationApplication.class).run(args);
}
}
Use configuration
@NacosValue/**
* Turn on autoRefreshed Configuration item , It can realize the dynamic refresh of parameters
*/
@NacosValue(value = "${demo.app.id}")
private String appId;
@NacosValue(value = "${demo.app.name}", autoRefreshed = true)
private String appName;
@NacosValue(value = "${demo.app.author}", autoRefreshed = true)
private String appAuthor;
- Fast QA: The example demonstrates only a few simple variable parameters , Can the connection configuration information of middleware such as database be placed in the configuration center ?
- Of course you can , Dry is finished .
Colored eggs : Log level hot switching based on configuration center
# journal
logging.level.root=INFO
logging.level.com.gitee.pulanos.pangu=INFO
This article related example source code
- pangu-examples-config-remote-nacos: Configuration center reference example
- pangu-examples-log-dynamic: Reference example of log level hot switching based on configuration center
Colored eggs
- Pangu open source homepage
- Pangu development documents
边栏推荐
- NFT market has entered the era of aggregation, and okaleido has become the first aggregation platform on BNB chain
- [go] introduction to exp
- MySQL learning notes - Chapter 5 - data backup and recovery, MySQL logs
- 无法在debug时进入ArrayList底层解决方案
- flutter setState() called after dispose()
- How much do you know, deep analysis, worth collecting
- Cyclodextrin metal organic framework loaded low molecular weight heparin and adriamycin (MOF metal organic framework loaded biological macromolecular drugs)
- Be sincere and open with gold and stone
- 第三章运输层
- DM 平台管理 - netcore
猜你喜欢

字符串切割 group by

Execution engine - (compiler, JIT)

Network planning | units of each layer in OSI model

Data asset management: how to manage the data assets of an enterprise?

Leetcode 2048. 下一个更大的数值平衡数(有点意思,已解决)

电脑的选择1

三维数字沙盘展示具备哪些应用优势

Mof-53nps loaded antibacterial molecule vancomycin (MOF metal organic framework loaded protein polypeptide drugs)

多引擎数据库管理工具 DataGrip 2022.1.5中文版

Music creation tool Steinberg Cubase Pro
随机推荐
建造者模式
In modern society, people are more and more dependent on semiconductor products
使用 KubeKey 搭建 Kubernetes/KubeSphere 环境的“心路(累)历程“
最新版,最新资料
Float float simulates double precision computation on CPU and GPU
EasyRecovery15免费版本数据恢复软件
第三章运输层
flutter 弹窗flutter_easyloading
最全知识总结,初学者必看
一次内存泄漏的问题记录
P1110 [zjoi2007] report statistics
精诚所至,金石为开
第二章应用层
首家BMW i品牌专属体验店开业,全面展示宝马电动产品的魅力
Leetcode 2048. 下一个更大的数值平衡数(有点意思,已解决)
Tidb cloud launched Google cloud marketplace, empowering global developers with a new stack of real-time HTAP databases
Daily question -1232 Dotted line
Jingzhida rushes to the scientific innovation board: the annual revenue is 458million, and the SME fund is the shareholder
文档书写规范
Matlab related function knowledge points (III) -floor function + dot division operator + matrix index rules