Chapter 3 Distributed Configuration Center
Why is a distributed configuration center needed
The distributed configuration center was introduced to solve the need for configuration management in distributed systems. In traditional monolithic applications, configuration files are usually used to centrally manage system configuration information. However, in distributed systems, the traditional configuration file approach will face some challenges as the system scale becomes larger, there are many nodes, and they may be deployed on different servers.
First of all, the modification and release of configuration files require manual operations, which becomes very cumbersome and error-prone if the system is large in scale. Secondly, configuration files are not easy to dynamically update. If a certain configuration needs to be modified, the entire application needs to be redeployed. For distributed systems, such operations will bring significant downtime and impact that cannot be ignored.
Therefore, the introduction of a distributed configuration center can solve these problems. The distributed configuration center provides a centralized management interface that can easily modify and publish configurations. At the same time, it supports real-time dynamic configuration update, which can make configuration modifications take effect immediately without restarting the application or redeploying. In addition, the distributed configuration center also provides functions such as configuration version management, permission control, and grayscale release of configuration items, which can better meet the configuration management needs of distributed systems.
What is a distributed configuration center
Distributed configuration center is a tool or service used to manage and centrally store distributed system configuration information. It provides a centralized platform to facilitate developers to uniformly manage and adjust system configurations to meet the needs of different environments.
.Net Distributed Configuration Center Usually has the following characteristics:
-
Centralized management: The distributed configuration center centrally stores the configuration information of each component or node in the system in one place to facilitate development people to view, modify and update.
-
Real-time update: The distributed configuration center supports dynamic update of configuration information. When configuration items change, the system can be notified in real time. nodes or components so that configuration modifications can take effect immediately without restarting the application.
-
Version control: The configuration center usually supports configuration version management, can record the modification history of each configuration, and supports rollback to previous version.
-
Permission control: In order to ensure the security of the configuration, the distributed configuration center provides a permission management mechanism that can restrict different roles or User access and modification rights to configuration.
-
Grayscale release: Some distributed configuration centers also support grayscale release of configuration, that is, configuration changes are only applied to some nodes. or users to verify and test new configurations step by step.
-
Supports IConfiguration, IOptions mode to read configuration, the original program almost does not need to be modified
By using the distributed configuration center, the team can manage and maintain the configuration of the distributed system more efficiently and reduce system configuration management complexity and improve the maintainability and flexibility of the system.
2. Nacos Configuration Center
Document address:
Installation
Omitted
How to use
-
nuget installation:
-
nacos-sdk-csharp
-
<span class="md-pl�is "how to do it". When writing code at a higher level, you are more concerned about the goal rather than the process of implementing the underlying algorithm. SummerBoot is committed to creating a humanized framework to make .net development simpler and more elegant.
SummberBoot currently supports only Nacos configuration center.
How to use
-
Delete the original Nacos configuration (clear it if any)
-
Install nuget package:
SummerBoot 2.0.2
-
appsetting.json Add the following configuration
"nacos": { //-- ------When using nacos, serviceAddress and namespaceId are required ------ //nacos service Address, such as http://172.16.189.242:8848 "serviceAddress": "http://127.0.0.1:8848/" , "namespaceId span>": "NetCloud", //-- ------If you need to use the nacos configuration center, ConfigurationOption is required ------ "configurationOption": { //Configured Group "groupName": "DEFAULT_GROUP", //Configured dataId, "dataId": "app-Development.json" } }
-
Program injection service
builder.Host.UseNacosConfiguration();
-
Test
[ApiController] [Route(" [controller]/[action]")] public class span> HomeController:ControllerBase { private readonly span>IConfiguration _configuration; public HomeController(IConfiguration configuration) { _configuration = configuration; } [HttpGet] public IActionResult Test1( ) { // Read nacos configuration center var connectionString = _configuration.GetConnectionString(" MySql" span>); return Ok(connectionString ); } }
Video supporting link: Course Introduction (cctalk.com)
The sea is broad and the fish are leaping, the sky is high and I can do whatever I want. Give me a piece of blue sky and let me fly freely.style=”color: rgba(0, 0, 0, 1)”>IActionResult Test1()
{
// Read nacos configuration center
var connectionString = _configuration.GetConnectionString(” MySql“ span>);
return Ok(connectionString );
}
}
-
Video supporting link: Course Introduction (cctalk.com)
The sea is broad and the fish are leaping, the sky is high and I can do whatever I want. Give me a piece of blue sky and let me fly freely.
-