# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=C:\\zookeeper-3.4.5\\data
dataLogDir=C:\\zookeeper-3.4.5\\log
# the port at which the clients will connect
clientPort=2181
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZooKeeperNet;
namespace ZookeeperDemo
{
class Watcher : IWatcher
{
public void Process(WatchedEvent @event)
{
if (@event.Type == EventType.NodeDataChanged)
{
Console.WriteLine(@event.Path);
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZooKeeperNet;
namespace ZookeeperDemo
{
class Program
{
static void Main(string[] args)
{
//创建一个Zookeeper实例,第一个参数为目标服务器地址和端口,第二个参数为Session超时时间,第三个为节点变化时的回调方法
using (ZooKeeper zk = new ZooKeeper("127.0.0.1:2181", new TimeSpan(0, 0, 0, 50000), new Watcher()))
{
var stat = zk.Exists("/root",true);
////创建一个节点root,数据是mydata,不进行ACL权限控制,节点为永久性的(即客户端shutdown了也不会消失)
//zk.Create("/root", "mydata".GetBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.Persistent);
//在root下面创建一个childone znode,数据为childone,不进行ACL权限控制,节点为永久性的
zk.Create("/root/childone", "childone".GetBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.Persistent);
//取得/root节点下的子节点名称,返回List<String>
zk.GetChildren("/root", true);
//取得/root/childone节点下的数据,返回byte[]
zk.GetData("/root/childone", true, null);
//修改节点/root/childone下的数据,第三个参数为版本,如果是-1,那会无视被修改的数据版本,直接改掉
zk.SetData("/root/childone", "childonemodify".GetBytes(), -1);
//删除/root/childone这个节点,第二个参数为版本,-1的话直接删除,无视版本
zk.Delete("/root/childone", -1);
}
}
}
}