simple zookeeper c++ bindings, zookeeper service monitor implemented via zookeeper c++ bindings. https://github.com/satanson/zk
Zk is built on conditions as follows:
- zookeeper 3.4.3 and 3.4.8
- g++ 4.8.4 (c++11 option enabled)
I don't build zk on other versions of zookeeper and g++.
ZK can be grasped in fews steps!
-
download zookeeper-3.4.8 and build c bindings of zookeeper
$ wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.8/zookeeper-3.4.8.tar.gz $ tar xzvf zookeeper-3.4.8.tar.gz $ cd zookeeper-3.4.8/src/c $ ./configure && make && sudo make install
-
build zk demos
$ ./build.sh $ ./zk_test -help $ ./zk_test 172.17.0.2:2181 /foobar $ ./build_zksm.sh $ ./zksm_test -help $ ./zksm_test 172.17.0.2:2181 /foobar
A standalone zookeeper instance or a zookeeper cluster should be started when trying zk_test and zksm_test. If you familiar with docker, image jplock/zookeeper can be played with for testing.
API manual You can learn how to use zk from demos(zk_test.cpp, zksm_test.cpp), which is quit easy!
- Zookeeper ctor: establish connection to Zookeeper cluster and create a session.
ZooKeeper(string const& connStr, int sessionTimeout,shared_ptr<Watcher> watcher)
override Watcher's virtual function void process(WatchedEvent &const)
- zk_create: create znode.
string zk_create(string const& path,string const& data,CreateMode createMode)
- zk_delete: delete znode.
void zk_delete(string const& path,int version)
- zk_exists: test if znode exists.
bool zk_exists(string const& path, bool watch)
- zk_getData: fetch data from znode.
string zk_getData(string const& path, bool watch)
- zk_setData: store data into znode.
void zk_setData(string const& path, string const& data, int version)
- zk_getChildren: get znode's children.
list<string> zk_getChildren(string const& path,bool watch)