public void should_get_setting_on_start_even_if_node_is_added_later() { var runner = ZkRunner.New().Path(() => Path) .ConnectionString(() => ConnectionString) .SessionTimeout(() => TimeSpan.FromSeconds(5)) .Build(); var client = runner.Start(); var reset = new AutoResetEvent(false); bool set = false; client.SubscribeOn <bool>("foo", x => { Console.WriteLine("[test] got update for foo"); set = x; reset.Set(); }); setData("{foo:true}"); reset.WaitOne(TimeSpan.FromSeconds(10)); Assert.IsTrue(set); setData("{foo:false}"); reset.WaitOne(TimeSpan.FromSeconds(10)); Assert.IsFalse(set); runner.Dispose(); }
private void Run() { var zk = ZkRunner.New() .Path(() => _path) .ConnectionString(() => "192.168.60.2:2181") .SessionTimeout(() => TimeSpan.FromSeconds(3)) .Build(); var togglez = zk.Start(); //waiting synchronously is optional. however, Get<> calls will return nulls / defaults until settings are ready. //using subscriptions where possible. subscriptions run on first connect, and everytime the path's value changes. //you only need to subcribe to a single setting for any particular path. In the handler, you can use togglez.Get<>(..) to //get the other values for the same path. //Get<> doesn't make a call to zk...it simply uses state that's already been fetched. As such, you either need to use //a subscription, or wait for settings for one time init. Console.WriteLine("Waiting for settings..."); togglez.WaitForFirstSettings(TimeSpan.FromSeconds(10)); Console.WriteLine("Got settings..."); Console.WriteLine(togglez.Get <int>("foo")); togglez.SubscribeOn <int>("foo", Console.WriteLine); Console.WriteLine(togglez.Get <int>("foo")); Console.ReadLine(); zk.Dispose(); }
private void Run() { var zk = ZkRunner.New() .Path(() => _path) .ConnectionString(() => "192.168.60.2:2181") .SessionTimeout(() => TimeSpan.FromSeconds(3)) .Build(); var togglez = zk.Start(); Console.WriteLine(togglez.Get <int>("foo")); togglez.SubscribeOn <int>("foo", Console.WriteLine); Console.WriteLine(togglez.Get <int>("foo")); //waiting synchronously is optional. Console.WriteLine("Waiting for settings..."); togglez.WaitForFirstSettings(TimeSpan.FromSeconds(10)); Console.WriteLine("Got settings..."); Console.ReadLine(); zk.Dispose(); }