2.0.0 • Published 6 years ago

egg-zookeeper v2.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

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