How to use the node-zookeeper-client.createClient function in node-zookeeper-client

To help you get started, we’ve selected a few node-zookeeper-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github scality / backbeat / lib / clients / zookeeper.js View on Github external
function createClient(connectionString, options) {
    const zkClient = zookeeper.createClient(connectionString, options);
    zkClient.once('connected', () => {
        // for some reason zkClient.exists() does not return
        // NO_NODE when base path does not exist, hence use
        // getData() instead
        zkClient.getData('/', err => {
            if (err && err.name !== 'NO_NODE') {
                return zkClient.emit('error', err);
            }
            // NO_NODE error and autoCreateNamespace is enabled
            if (err && options && options.autoCreateNamespace) {
                const nsIndex = connectionString.indexOf('/');
                const hostPort = connectionString.slice(0, nsIndex);
                const namespace = connectionString.slice(nsIndex);
                const rootZkClient = zookeeper.createClient(hostPort, options);
                rootZkClient.connect();
                return rootZkClient.mkdirp(namespace, err => {
github NetEase / pomelo / lib / monitors / zookeepermonitor.js View on Github external
}, (next) => { // fn
    count++;
    logger.debug('%s server is try to connect to zookeeper',
                 mon.app.serverId);
    mon.client.close();
    mon.client = zookeeper.createClient(mon.servers, {
      sessionTimeout: mon.timeout,
      retries: 0,
      spinDelay: mon.spinDelay
    });

    mon.cbTimer = setTimeout(() => {
      logger.info('reconnect to zookeeper timeout');
      mon.state = ZK_CONNECT_FAIL;
      utils.invokeCallback(next);
    }, constants.TIME.DEFAULT_ZK_CONNECT_TIMEOUT);

    mon.client.once('connected', () => {
      logger.info('%s connect zookeeper successfully.', mon.app.serverId);

      mon.state = ZK_CONNECTED;
      mon.client.addAuthInfo('digest', new Buffer(mon.authentication));
github XadillaX / illyria2 / lib / illyria-zk.js View on Github external
this.connectingString = connectingString;
    this.options = options;
    this.root = root || "/illyria";
    this.prefix = prefix || "/t";
    this.path = null;

    this.root = this.root.trim();
    this.prefix = this.prefix.trim();

    if(!this.root.length) this.root = "/illyria";
    if(this.root[0] !== "/") this.root = "/" + this.root;
    if(!this.prefix.length) this.prefix = "/t";
    if(this.prefix[0] !== "/") this.prefix = "/" + this.prefix;

    // zookeeper core object
    this.client = zookeeper.createClient(this.connectingString, options);
    this.server = {
        host: "127.0.0.1",
        port: 3721,

        clients: 0
    };

    this.clientStatus = ZK_STATUS.NOT_CONNECTED;
};
github scality / backbeat / tests / functional / lib / ProvisionDispatcher.spec.js View on Github external
before(done => {
        const zkClient = zookeeper.createClient('localhost:2181');
        zkClient.connect();
        zkClient.on('connected', () => {
            zkClient.mkdirp(ZK_TEST_PATH, err => {
                assert.ifError(err);
                const prov = new ProvisionDispatcher(zkConf);
                prov.addProvisions(provisionList, done);
            });
        });
    });
    afterEach(done => {
github scality / backbeat / extensions / clueso / queuePopulator / QueuePopulator.js View on Github external
_setupZookeeper(done) {
        const populatorZkPath = this.cluesoConfig.queuePopulator.zookeeperPath;
        const zookeeperUrl =
            `${this.zkConfig.connectionString}${populatorZkPath}`;
        this.log.info('opening zookeeper connection for persisting ' +
                      'populator state',
                      { zookeeperUrl });
        this.zkClient = zookeeper.createClient(zookeeperUrl);
        console.log("creating zookeeper client!!", this.zkClient);
        this.zkClient.connect();
        console.log("just called connect!!")
        this._readLogOffset((err, offset) => {
            console.log("in callback for read offset log", err, offset);
            if (err) {
                return done(err);
            }
            this.logOffset = offset;
            return done();
        });
    }
github omnip620 / node-zookeeper-dubbo / index.js View on Github external
initClient() {
    this.client = zookeeper.createClient(this.registry, {
      sessionTimeout: 30000,
      spinDelay: 1000,
      retries: 5
    });

    this.client.connect();
    this.client.once("connected", this.onOnceConnected.bind(this));

    this.checkConnection();
  }
github XadillaX / illyria2 / lib / zookeeper.js View on Github external
this.connectString = connectString;
    this.options = options;
    this.root = root || "/illyria";
    this.prefix = prefix || "/HB_";
    this.path = null;

    this.root = this.root.trim();
    this.prefix = this.prefix.trim();

    if(!this.root.length) this.root = "/illyria";
    if(!this.prefix.length) this.prefix = "/HB_";
    if(this.root[0] !== "/") this.root = "/" + this.root;
    if(this.prefix[0] !== "/") this.prefix = "/" + this.prefix;

    this.client = zookeeper.createClient(this.connectString, options);
    this.server = {
        host: "127.0.0.1",
        port: 3721,

        clients: 0
    };

    this.clientStatus = ZK_STATUS.NOT_CONNECTED;

    this._setup();
};
github Corey600 / zoodubbo / index.js View on Github external
function ZD(conf) {
    if (!(this instanceof ZD)) return new ZD(conf);
    conf = conf || {};
    this._dubbo = conf.dubbo;
    this._conn = conf.conn;
    this._client = this.client = zookeeper.createClient(this._conn, {
        sessionTimeout: conf.sessionTimeout,
        spinDelay: conf.spinDelay,
        retries: conf.retries
    });

    this._cache = this.cache = {};
}
github xpush / node-xpush / lib / xpush.js View on Github external
module.exports.createZookeeperClient = function(options) {

  var zookeeper = require('node-zookeeper-client');
  var addr = 'localhost:2181';
  if (options.zookeeper) {
    if (typeof options.zookeeper === 'string' || options.zookeeper instanceof String) {
      addr = options.zookeeper;
    } else {
      if (options.zookeeper.address) addr = options.zookeeper.address;
    }
  }
  var zkClient = zookeeper.createClient(addr, {
    retries: 2
  });

  return zkClient;

};
module.exports.createRedisManager = function(options) {