AgileConfig

This is a lightweight configuration center based on.net Core.

  1. The deployment is simple, requiring at least one data node and supporting docker deployment
  2. Supports distributed deployment of multiple nodes to ensure high availability
  3. Applications support inheritance, where common configurations can be extracted into one application and then inherited by other applications
  4. The configuration supports application isolation, and the intra-application configuration supports group isolation
  5. Using the long-link technology, the configuration information is pushed to the client in real time
  6. Support IConfiguration, IOptions mode read configuration, the original program can almost without transformation
  7. Configuration modification support version record, roll back configuration at any time
  8. If all nodes fail, the client supports reading the configuration from the local cache

Client project AgileConfig_Client Example project AgileConfigMVCSample

architecture

AgileConfig’s architecture is relatively simple, mainly divided into three parts:

The client

The client program is a class library developed by netstandard2.0, which is convenient for.net core program access. Nuget search agileconfig. Client can be installed. You can configure the addresses of multiple nodes when starting the client. The client randomly selects one node for connection and maintains a WebSocket long connection after successful connection. If the connection is interrupted due to the failure of the connected node, the client continues to connect to a random node until the connection is successful.

Node, hypervisor

A node is a service developed using ASP.NET Core. For easy deployment, the hypervisor and node services are integrated directly. Any node can configure environment variables at startup to enable the hypervisor function.

The database

Use database to store data, currently support Sqlserver, Mysql, Sqlite, PostgreSql,Oracle five databases. The latest version has switched to Freesql as the data access component. Freesql has stronger support for multiple databases, especially for domestic databases. However, because there is no test environment of domestic database, this project is not supported. If necessary, I can open a branch to try to support it, but the test work depends on users.

Note: Do not update EFCore if you are using a version <=1.0.4, because there may be some differences between EFCore and Freesql automatically built libraries.

Deploying the server

Initializing the database

The user only needs to manually create an empty library, and all the tables will be automatically generated at the first startup. Currently supports sqlserver, mysql, sqlite, PostgreSql, and Oracle databases. Provider: SQLServer = SQLServer mysql = mysql sqLite = sqLite NPGSQL = PostgreSql Oracle = Oracle

Using the server

Running the server

sudo docker run --name agile_config -e adminConsole=true -e db:provider=sqlite -e db:conn="Data Source=agile_config.db" -p 5000:5000 kklldog/agile_config:latest
Copy the code

Create an agile_config instance with Docker, which has 3 environment variables to be configured:

  1. Whether the adminConsole configurator is the administrative console. If true, console functionality is enabled and an administrative interface appears when accessing the instance.
  2. Db: database type of the provider configuration program. Currently program support: SQLite, mysql, SQLServer, NPGSQL, Oracle five databases.
  3. Db :conn Configures the database connection string

Example Initialize the administrator password

You need to initialize the administrator password the first time you run the program

node

AgileConfig supports multi-node deployment, where all nodes are parallel. To simplify deployment, AgileConfig does not have a separate console program, so use any node as the console. When the environment variable adminConsole=true, this node functions as both data node and console. In order for the console to manage the nodes, you need to configure the node information on the console.

Note: Even the data node that acts as the console needs to be added to the hypervisor in order to manage it.

application

AgileConfig supports multiple application access. You need to configure the name, ID, secret key, and so on for each application. Each application can set whether or not it can be inherited, which is similar to Apollo’s concept of a common namespace. A common configuration can be extracted from an inheritable application, and other applications can obtain all configurations simply by inheriting it. If the configuration keys of the child application and the inherited application duplicate, the configuration of the child application overwrites that of the inherited application. Subapplications can inherit multiple applications. If duplicate keys occur between multiple applications, the configuration of the inherited application overrides the previous application.

Configuration items

After configuring application information, you can configure configuration items for each application. Configuration items support groups. The newly added configuration is not detected by the client. You need to manually click Online to push the configuration to the client. If online configurations are modified, deleted, or rolled back, they are pushed to the client in real time. Version history records the historical information about configurations and can be rolled back to any version.

The client

The console allows you to view connected clients.

The system log

The system logs record some key information in AgileConfig production.

Using the client

AgileConfig_Client is a class library written using.net core standard2.0 and released to nuget for easy user integration.

Install the client class library using Nuget

Install-Package AgileConfig.Client
Copy the code

Initialize the client

Take the asp.net core MVC project for example:

{ "Logging": { "LogLevel": { "Default": "Information", "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" } }, "AllowedHosts": "*", //agile_config "AgileConfig": { "appId": "app", "secret": "xxx", "nodes": "Http://localhost:5000, http://localhost:5001 / / multiple nodes separated by a comma}}Copy the code
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureAppConfiguration((context, Config) = > {/ / read local configuration var localconfig = new ConfigurationBuilder () SetBasePath (Directory. The GetCurrentDirectory ()) .AddJsonFile("appsettings.json").Build(); Var appId = localConfig ["AgileConfig:appId"]; var secret = localconfig["AgileConfig:secret"]; var nodes = localconfig["AgileConfig:nodes"]; Var configClient = new configClient (appId, secret, Nodes); // Use AddAgileConfig to configure a new IConfigurationSource config.AddAgileConfig(configClient); // Find a variable to mount the client instance, so that other places can use the instance directly to access ConfigClient = ConfigClient; / / register configuration items modified event configClient ConfigChanged + = ConfigClient_ConfigChanged; }) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });Copy the code

Reading configuration

AgileConfig supports asp.net core standard IConfiguration and reads configuration with IOptions mode. It also supports reading directly from the AgileConfigClient instance:

public class HomeController : Controller { private readonly ILogger<HomeController> _logger; private readonly IConfiguration _IConfiguration; private readonly IOptions<DbConfigOptions> _dbOptions; public HomeController(ILogger<HomeController> logger, IConfiguration configuration, IOptions<DbConfigOptions> dbOptions) { _logger = logger; _IConfiguration = configuration; _dbOptions = dbOptions; } public IActionResult Index() { return View(); } /// </ / update /// / { var userId = _IConfiguration["userId"]; var dbConn = _IConfiguration["db:connection"]; ViewBag.userId = userId; ViewBag.dbConn = dbConn; return View(); } /// </summary> // </returns> public IActionResult ByInstance() { var userId = Program.ConfigClient["userId"]; var dbConn = Program.ConfigClient["db:connection"]; ViewBag.userId = userId; ViewBag.dbConn = dbConn; return View("ByIConfiguration"); } /// <summary> // </returns> public IActionResult ByOptions() {var dbConn  = _dbOptions.Value.connection; ViewBag.dbConn = dbConn; return View("ByIConfiguration"); }}Copy the code

To contact me

What problem can mail me: [email protected] can also add QQ group: 1022985150