DotNet.MultiSourceConfiguration.Zookeeper 0.1.0

.NET Framework 4.5
There is a newer version of this package available.
See the version list below for details.
NuGet\Install-Package DotNet.MultiSourceConfiguration.Zookeeper -Version 0.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
dotnet add package DotNet.MultiSourceConfiguration.Zookeeper --version 0.1.0
<PackageReference Include="DotNet.MultiSourceConfiguration.Zookeeper" Version="0.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DotNet.MultiSourceConfiguration.Zookeeper --version 0.1.0
#r "nuget: DotNet.MultiSourceConfiguration.Zookeeper, 0.1.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install DotNet.MultiSourceConfiguration.Zookeeper as a Cake Addin
#addin nuget:?package=DotNet.MultiSourceConfiguration.Zookeeper&version=0.1.0

// Install DotNet.MultiSourceConfiguration.Zookeeper as a Cake Tool
#tool nuget:?package=DotNet.MultiSourceConfiguration.Zookeeper&version=0.1.0


Build Status NuGet Version

Zookeeper configuration source for the DotNet.MultiSourceConfiguration library, based on the ZooKeeper.Net ZooKeeper client.

How to use it

You can add ZookeeperConfigSource as a configuration source for your IConfigurationBuilder (from DotNet.MultiSourceConfiguration). You need to provide an instance of IZooKeeper (from ZooKeeper.Net) to the ZookeeperConfigSource, for it to be able to connect ZooKeeper. In addition you need to provide a base path, which is the base path in ZooKeeper for the nodes containing your configuration properties.

    using MultisourceConfiguration;
    using MultisourceConfiguration.Zookeeper;
    using ZooKeeperNet;
    class Program
        static void Main(string[] args)
            IConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
            IZooKeeper zooKeeper = new ZooKeeper("localhost:2181", TimeSpan.TimeSpan.FromSeconds(30), new ZooKeeperConfigWatcher());
            configurationBuilder.AddSources(new ZookeeperConfigSource(zooKeeper, "/path/to/config/in/zookeeper"));
            TestConfigurationDto configurationInterface = configurationBuilder.Build<TestConfigurationDto>();
    class ZooKeeperConfigWatcher: IWatcher 
        // This method will get invoked every time the ZooKeeper status or configuration values change.
        // This way you can dinamically react to changes in configuration.
        public void Process(WatchedEvent @event) 

Assuming that the test configuration DTO used in this example is like this:

    public class TestConfigurationDto
        // By default properties are not required
        public int? IntProperty { get; set; }

when the configuration is built using configurationBuilder.Build<TestConfigurationDto>(), DotNet.MultisourceConfiguration.Zookeeper will target ZooKeeper (using the IZooKeeper client instance you provided to it), and will attempt to retrieve the data from a configuration node with path /path/to/config/in/zookeeper/ DotNet.MultisourceConfiguration.Zookeeper assumes that all the string configuration data in ZooKeeper is stored in UTF-8.

Bootstrapping the ZooKeeper Configuration

It very probable that will want to read the ZooKeeper connection string (comma separated list of host:port) and the session timeout from configuration, instead of hard-coding it. You may read that configuration from your IConfigurationBuilder, taking advantage of other configuration sources, like AppSettingsSource, EnvironmentVariableSource or CommandLineSource.

        IConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
                new AppSettingsSource(), new EnvironmentVariableSource(), new CommandLineSource(args));
        // MyZooKeeperConfig must be a class you define that will hold the configuration for ZooKeeper.
        MyZooKeeperConfig myZooKeeperConfig = configurationBuilder.Build<MyZooKeeperConfig>();

        IZooKeeper zooKeeper = new ZooKeeper(myZooKeeperConfig.ConnectionString, myZooKeeperConfig.SessionTimeOut, new ZooKeeperConfigWatcher());
        configurationBuilder.AddSources(new ZookeeperConfigSource(zooKeeper, "/path/to/config/in/zookeeper"));
Product Versions
.NET Framework net45 net451 net452 net46 net461 net462 net463 net47 net471 net472 net48
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.3.0 911 11/14/2017
0.2.1 735 11/14/2017
0.2.0 616 11/13/2017
0.1.0 790 11/9/2017

First version.