Socket
Socket
Sign inDemoInstall

zookeeper-cluster-client

Package Overview
Dependencies
46
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    zookeeper-cluster-client

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


Version published
Maintainers
2
Created

Readme

Source

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

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

Extends APIs

Provides some useful APIs beyond node-zookeeper-client.

  • 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);
    });
    
  • 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

FAQs

Last updated on 27 Dec 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc