Deep dive into Nacos Config implementation principles
Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.
Nacos Config implementation principle analysis
Nacos Config provides four operations for configuration management, and Nacos provides SDK and Open API access for these four operations.
- Get the configuration, read the configuration from Nacos Config Server
SDK:
public String getConfig(String dataId,String group,long timeMills) throws NacosException;
API:
/nacos/v1/c/configs(get)
Copy the code
-
Listening configuration: Subscribes to a configuration and receives an event when the configuration changes
SDK: public void addListener(String dataId,String group,Listener listener); API: /nacos/v1/cs/configs(POST) Copy the code
-
Publish the configuration: Save the configuration to Nacos Config Server
SDK:
public boolean publishConfig(String dataId,String group,String content) throws Nacosexception;
API:
/nacos/v1/cs/configs
Copy the code
- Delete configuration: Delete the configuration center
SDK:
public boolean removeConfig(String dataId,String group) throws NacosException;
API:
/nacos/v1/cs/configs(DELETE)
Copy the code
In general, there are two types: configuration new, modify, delete, query and configuration dynamic listening.
Configure add delete change check
Nacos Config mainly provides centralized configuration management function externally, and provides access interface for adding, deleting, modifying, and checking to complete basic configuration operations. From the perspective of the server, the configuration of how to store, and whether to persist, the client needs to obtain the configuration from the server through the interface.
Note:
The Derby database is the default data store for Nacos Server, and mysql is also supported.
Dynamic monitoring
When configuration changes of Nacos Congfig Server occur, relevant clients need to be aware of configuration changes and obtain the latest configuration. How does the Nacos client implement configuration updates when configuration changes occur?