DotNet.MultiSourceConfiguration.Zookeeper
0.3.0
dotnet add package DotNet.MultiSourceConfiguration.Zookeeper --version 0.3.0
NuGet\Install-Package DotNet.MultiSourceConfiguration.Zookeeper -Version 0.3.0
<PackageReference Include="DotNet.MultiSourceConfiguration.Zookeeper" Version="0.3.0" />
paket add DotNet.MultiSourceConfiguration.Zookeeper --version 0.3.0
#r "nuget: DotNet.MultiSourceConfiguration.Zookeeper, 0.3.0"
// 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
DotNet.MultisourceConfiguration.Zookeeper
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
[Property("test.int.property")]
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/test.int.property
. 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();
configurationBuilder.AddSources(
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"));
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
-
- DotNet.MultiSourceConfiguration (>= 0.5.0 && < 1.0.0)
- ZooKeeperNetEx (>= 3.0.0 && < 4.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Updated to the new interface of configuration source, in DotNet.MultisourceConfiguration v0.5, that accepts a cache expiration.