DotNet.MultiSourceConfiguration.Zookeeper 0.3.0

Install-Package DotNet.MultiSourceConfiguration.Zookeeper -Version 0.3.0
dotnet add package DotNet.MultiSourceConfiguration.Zookeeper --version 0.3.0
<PackageReference Include="DotNet.MultiSourceConfiguration.Zookeeper" Version="0.3.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.3.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: DotNet.MultiSourceConfiguration.Zookeeper, 0.3.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.3.0

// Install DotNet.MultiSourceConfiguration.Zookeeper as a Cake Tool
#tool nuget:?package=DotNet.MultiSourceConfiguration.Zookeeper&version=0.3.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.


NuGet Version

Zookeeper configuration source for the DotNet.MultiSourceConfiguration library, based on the ZooKeeperNetEx 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 ZooKeeper (from ZooKeeperNetEx) 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 org.apache.zookeeper;
    class Program
        static void Main(string[] args)
            IConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
            ZooKeeper zooKeeper = new ZooKeeper("localhost:2181", 30000, new ZooKeeperConfigWatcher());
            configurationBuilder.AddSources(new ZookeeperConfigSource(zooKeeper, "/path/to/config/in/zookeeper"));
            TestConfigurationDto configurationInterface = configurationBuilder.Build<TestConfigurationDto>();
    class ZooKeeperConfigWatcher: Watcher 
        // 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 Task process(WatchedEvent @event)
			return new Task( () => {} );

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

You will very probably 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>();

        ZooKeeper zooKeeper = new ZooKeeper(myZooKeeperConfig.ConnectionString, myZooKeeperConfig.SessionTimeOut.Value, new ZooKeeperConfigWatcher());
        configurationBuilder.AddSources(new ZookeeperConfigSource(zooKeeper, "/path/to/config/in/zookeeper"));

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 715 11/14/2017
0.2.1 570 11/14/2017
0.2.0 495 11/13/2017
0.1.0 617 11/9/2017

Updated to the new interface of configuration source, in DotNet.MultisourceConfiguration v0.5, that accepts a cache expiration.