Giter Club home page Giter Club logo

configuration-service's Introduction

Configuration Service

Build

Package Latest Release
ConfigurationService.Hosting NuGet Badge ConfigurationService.Hosting
ConfigurationService.Client NuGet Badge ConfigurationService.Client

About Configuration Service

Configuration Service is a remote configuration service for .NET Core. Configuration for fleets of applications, services, and containerized micro-services can be updated immediately without the need to redeploy or restart. Configuration Service uses a client/server pub/sub architecture to notify subscribed clients of configuration changes as they happen. Configuration can be injected using the standard options pattern with IOptions, IOptionsMonitor or IOptionsSnapshot.

Configuration Service currently supports hosting configuration with either git or a file system and supports publishing changes with Redis or RabbitMQ publish/subscribe. File types supported are .json, .yaml, .xml and .ini.

Configuration Service Diagram

Features

  • RESTful HTTP based API for external configuration.
  • Server easily integrates into an ASP.NET Core application.
  • Client easily integrates into any .NET Standard 2.0 application using the standard ConfigurationBuilder pattern.
  • Client encapsulates real-time configuration updates.
  • Support for git and file system based storage.
  • Support for .json, .yaml, .xml and .ini configuration files.
  • Inject configuration with IOptionsMonitor or IOptionsSnapshot to access configuration changes.

Installing with NuGet

The easiest way to install Configuration Service is with NuGet.

In Visual Studio's Package Manager Console, enter the following command:

Server:

Install-Package ConfigurationService.Hosting

Client:

Install-Package ConfigurationService.Client

Adding the Configuration Service Host

The Configuration Service host middleware can be added to the service collection of an existing ASP.NET Core application. The following example configures a git storage provider with a Redis publisher.

public void ConfigureServices(IServiceCollection services)
{
    services.AddControllers();

    services.AddConfigurationService()
        .AddGitProvider(c =>
        {
            c.RepositoryUrl = "https://example.com/my-repo/configuration.git";
            c.Username = "username";
            c.Password = "password";
            c.LocalPath = "C:/config";
        })
        .AddRedisPublisher("localhost:6379");
}

In Startup.Configure, call MapConfigurationService on the endpoint builder. The default pattern is "/configuration".

app.UseEndpoints(endpoints =>
{
    endpoints.MapConfigurationService();
});

The configured host will expose two API endpoints:

  • configuration/ - Lists all files at the configured provider.
  • configuration/{filename} - Retrieves the contents of the specified file.

Git Provider Options

Property Description
RepositoryUrl URI for the remote repository.
Username Username for authentication.
Password Password for authentication.
Branch The name of the branch to checkout. When unspecified the remote's default branch will be used instead.
LocalPath Local path to clone into.
SearchPattern The search string to use as a filter against the names of files. Defaults to no filter (*).
PollingInterval The interval to check for remote changes. Defaults to 60 seconds.
services.AddConfigurationService()
    .AddGitProvider(c =>
    {
        c.RepositoryUrl = "https://example.com/my-repo/my-repo.git";
        c.Username = "username";
        c.Password = "password";
        c.Branch = "master";
        c.LocalPath = "C:/config";
        c.SearchPattern = ".*json";
        c.PollingInterval = TimeSpan.FromSeconds(60);
    }
    ...

File System Provider Options

Property Description
Path Path to the configuration files.
SearchPattern The search string to use as a filter against the names of files. Defaults to no filter (*).
IncludeSubdirectories Includes the current directory and all its subdirectories. Defaults to false.
Username Username for authentication.
Password Password for authentication.
Domain Domain for authentication.
services.AddConfigurationService()
    .AddFileSystemProvider(c => 
    {
        c.Path = "C:/config";
        c.SearchPattern = "*.json";
        c.IncludeSubdirectories = true;
    })
    ...

Custom Storage Providers and Publishers

Custom implementations of storage providers and publishers can be added by implementing the IProvider and IPublisher interfaces and calling the appropriate extension methods on AddConfigurationService:

services.AddConfigurationService()
    .AddCustomProvider(new CustomStorageProvider())
    .AddCustomPublisher(new CustomPublisher());

Adding the Configuration Service Client

The Configuration Service client can be configured by adding AddRemoteSource to the standard configuration builder. In the following example, remote json configuration is added and a Redis endpoint is specified for configuration change subscription. Local configuration can be read for settings for the remote source by using multiple instances of the configuration.

var loggerFactory = LoggerFactory.Create(builder =>
{
    builder.AddConsole();
});

IConfiguration configuration = new ConfigurationBuilder()
    .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
    .Build();

configuration = new ConfigurationBuilder()
    .AddConfiguration(configuration)
    .AddRemoteSource(s => 
    {
        s.ConfigurationName = "text.json";
        s.ConfigurationServiceUri = "http://localhost:5000/configuration/";
        s.Subscriber = () => new RedisSubscriber("localhost:6379");
        s.Optional = false;
        s.ReloadOnChange = true;
        s.LoggerFactory = loggerFactory;
    })
    .Build();

Configuration Soruce Options

Property Description
ConfigurationName Path or name of the configuration file relative to the configuration provider. This value should match the value specified in the list returned by the configuration/ endpoint.
ConfigurationServiceUri Configuration service endpoint.
Optional Determines if loading the file is optional.
ReloadOnChange Determines whether the source will be loaded if the underlying file changes.
HttpMessageHandler The optional HttpMessageHandler for the HttpClient.
RequestTimeout The timeout for the HttpClient request to the configuration server. Defaults to 60 seconds.
Parser The type used to parse the remote configuration file. The client will attempt to resolve this from the file extension of ConfigurationName if not specified.

Supported Types:
  • JsonConfigurationFileParser
  • YamlConfigurationFileParser
  • XmlConfigurationFileParser
  • IniConfigurationFileParser
Subscriber Delegate to create the type of ISubscriber used to subscribe to published configuration messages.
LoggerFactory The type used to configure the logging system and create instances of ILogger. Defaults to NullLoggerFactory.

Samples

Samples of both host and client implementations can be viewed at Samples.

Build history

configuration-service's People

Contributors

jamespratt avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.