egg-zookeeper

2.0.0 • Public • Published

egg-zookeeper

NPM version build status Test coverage David deps Known Vulnerabilities NPM download

egg plugin for zookeeper

Install

npm i egg-zookeeper --save

Usage

  1. Install & enable the plugin in egg
// config/plugin.js
exports.zookeeper = {
  enable: true,
  package: 'egg-zookeeper',
};
  1. 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.

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i egg-zookeeper

Weekly Downloads

0

Version

2.0.0

License

MIT

Unpacked Size

6.94 kB

Total Files

8

Last publish

Collaborators

  • gxcsoccer
  • fengmk2