Create zk client with app.zk.createClient(connectionString) api
const client = app.zk.createClient('localhost:2181');
yield client.ready();
const path = '/test-path';
function listChildren(client, path) {
client.getChildren(
path,
event => {
console.log('Got watcher event: %s', event);
listChildren(client, path);
},
(err, children, stat) => {
if (err) {
console.log('Failed to list children of %s due to: %s.', path, err);
return;
}
console.log('Children of %s are: %j.', path, children);
}
);
}
// create a new path
client.create(path, err => {
if (err) {
console.log('Failed to create node: %s due to: %s.', path, err);
} else {
console.log('Node: %s is successfully created.', path);
}
// list and watch the children of given node
listChildren();
});
egg-zookeeper
egg plugin for zookeeper
Install
Usage
app.zk.createClient(connectionString)apiAPIs
Please refer to zookeeper-cluster-client in detail.
License
MIT