Package detail

zookeeper-cluster-client

node-modules357MIT3.1.1

Sharing one zookeeper connection among Multi-Process on Node.js

readme

zookeeper-cluster-client

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

Support cluster-client process model on node-zookeeper-client.

Install

npm i zookeeper-cluster-client --save

Usage

1. Create a node using given path:

const zookeeper = require('zookeeper-cluster-client');
const client = zookeeper.createClient('localhost:2181');
const path = process.argv[2];

client.once('connected', async function() {
  await client.create(path);
  console.log('Node: %s is successfully created.', path);
  await client.close();
});

client.connect();

2. List and watch the children of given node:

const zookeeper = require('zookeeper-cluster-client');
const client = zookeeper.createClient('localhost:2181');
const path = process.argv[2];

async function listChildren(client, path) {
  const children = await client.getChildren(
    path,
    event => {
      console.log('Got watcher event: %s', event);
      listChildren(client, path);
    });
  console.log('Children of %s are: %j.', path, children);
}

client.once('connected', () => {
  console.log('Connected to ZooKeeper.');
  listChildren(client, path);
});

client.connect();

Support APIs

  • [x] createClient(connectionString, [options])
  • [x] connect()
  • [x] close(): return promise
  • [x] async create(path, [data], [acls], [mode])
  • [x] async remove(path, [version])
  • [x] async setData(path, data, [version])
  • [x] async getACL(path, [options])
  • [x] async setACL(path, acls, [version])
  • [x] async mkdirp(path, [data], [acls], [mode])
  • [x] async exists(path, [watcher])
  • [x] async getChildren(path, [watcher], [options])
  • [x] async getData(path, [watcher], [options])
  • [ ] addAuthInfo(scheme, auth)
  • [x] State getState()
  • [x] Buffer getSessionId()
  • [x] Buffer getSessionPassword()
  • [x] Number getSessionTimeout()
  • [ ] transaction()

Extends APIs

Provides some useful APIs beyond node-zookeeper-client.

  • [x] watch(path, listener)

    client.watch('/foo', (err, data, stat) => {
      if (err) {
        // handle error
        return;
      }
      console.log('data => %s', data.toString());
      console.log('stat => %s', stat);
    });
  • [x] watchChildren(path, listener)

    client.watchChildren('/foo', (err, children, stat) => {
      if (err) {
        // handle error
        return;
      }
      console.log('children => %j', children);
      console.log('stat => %s', stat);
    });

License

MIT

changelog

3.1.1 / 2021-12-27

fixes

  • [64a2ce6] - fix: 🐛 fix map keys occur memory leak (循环遍历map keys 导致内存泄漏) (#14) (wuteng606 <wuteng606@163.com>)

3.1.0 / 2019-06-19

features

3.0.0 / 2019-03-26

features

2.0.1 / 2018-04-12

fixes

2.0.0 / 2018-03-30

features

fixes

1.1.1 / 2017-08-23

fixes

1.1.0 / 2017-08-18

features

1.0.2 / 2017-08-17

fixes

1.0.1 / 2017-08-16

fixes

1.0.0 / 2017-07-31

  • init version release