egg-zookeeper
v2.0.0
Published
egg plugin for zookeeper
Downloads
11
Readme
egg-zookeeper
egg plugin for zookeeper
Install
npm i egg-zookeeper --save
Usage
- Install & enable the plugin in egg
// config/plugin.js
exports.zookeeper = {
enable: true,
package: 'egg-zookeeper',
};
- 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();
});
APIs
Please refer to zookeeper-cluster-client in detail.