npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

zen-zoodubbo

v1.0.2

Published

A Javascript module for Node.js to connect Dubbo service by node-zookeeper-client.

Downloads

5

Readme

zoodubbo

Build Status Coverage Status NPM Downloads NPM Version License

A Javascript module for Node.js to connect Dubbo service by node-zookeeper-client.

Features

  • Invoke Dubbo service as a Customer.
  • Use Zookeeper as the Dubbo Registration Center.
  • Only supports the use of the default hessian2 protocol for serialization and deserialization.
  • It is not very friendly to support the return value containing an enum type.
  • Use Random LoadBalance to choose Provider.
  • Use generic-pool to manage net.Socket.

Installation

You can install it using npm:

$ npm install zoodubbo

Example

var ZD = require('zoodubbo');
var zd = new ZD({
    // config the addresses of zookeeper
    conn: 'localhost:2181'
});

// connect to zookeeper
zd.connect();

// get a invoker with a service path
var invoker = zd.getInvoker('com.demo.Service');

// excute a method with parameters
var method = 'getUserByID';
var arg1={$class:'int',$:123};
invoker.excute(method, [arg1], function (err, data) {
    if (err) {
        console.log(err);
        return;
    }
    console.log(data)
});

Documentation

new ZD(conf)

Arguments

  • conf {String|Object} - A string of host:port pairs like conn. Or an object to set the instance options. Currently available options are:

    • dubbo {String} - Dubbo version information.

    The following content could reference: https://github.com/alexguan/node-zookeeper-client#client-createclientconnectionstring-options

    • conn {String} - Just like connectionString of node-zookeeper-client. Comma separated host:port pairs, each represents a ZooKeeper server.
    • sessionTimeout {Number} - Session timeout in milliseconds, defaults to 30 seconds.
    • spinDelay {Number} - The delay (in milliseconds) between each connection attempts.
    • retries {Number} - The number of retry attempts for connection loss exception.

Example

// use a string of host:port pairs
var zd = new ZD('localhost:2181,localhost:2182');

// use an object to set the instance options
var zd = new ZD({
    conn: 'localhost:2181,localhost:2182',
    dubbo: '2.5.3'
});

client

The client instance created by node-zookeeper-client. To listen event such as follows:

zd.client.on('connected', function connect() {
    console.log('zookeeper client connected!');
});

The list of events could reference: https://github.com/alexguan/node-zookeeper-client#state


void connect()

Connect to the Dubbo Registration Center by node-zookeeper-client. Equivalent to the following code:

zd.connect();
// just like
zd.client.connect();

void close()

Close the connection of node-zookeeper-client. Equivalent to the following code:

zd.close();
// just like
zd.client.close();

Invoker getInvoker(path[, opt])

Arguments

  • path {String} - Path of service.

  • opt {Object} - An object to set the Invoker options. Currently available options are:

    • version {String} - Service version information.
    • timeout {Number} - The timeout (in milliseconds) to excute.

    The following content could reference: generic-pool

    • poolMax {Number} - Maximum number of net.Socket to create from pool at any given time. Defaults to 1 .
    • poolMin {Number} - Minimum number of net.Socket to keep in pool at any given time. If this is set >= poolMax, the pool will silently set the min to equal max. Defaults to 0 .

Example

var invoker = zd.getInvoker('com.demo.Service', {
    version: '0.0.0'
});

new Invoker(zk[, opt])

Also you can create Invoker instance by URIs of providers directly.

Arguments

  • zk {Client|String|Array} - The ZD instance or the URIs of providers.

  • opt {Object} - An object to set the instance options. Currently available options are:

    • path {String} - Path of service.
    • dubbo {String} - Dubbo version information.

    The other content is same as the opt in getInvoker(path[, opt])

Example

var invoker = new ZD.Invoker(
  'dubbo://127.0.0.1:20880/com.demo.DemoService?interface=com.demo.DemoService&methods=sayHello',
  { version: '0.0.0' }
);

void excute(method, args[, cb])

Arguments

  • method {String} - Method to excute.
  • args {Array} - Argument list.
  • cb(err, data) {Function} - The data is the returned value. When the cb is undefined, the function return a Promise instance.

Example

var method = 'getUserByID';
var arg1={$class:'int',$:123};

// use callback
invoker.excute(method, [arg1], function (err, data) {
    if (err) {
        console.log(err);
        return;
    }
    console.log(data)
});

// or return a Promise instance
invoker.excute(method, [arg1])
    .then(function(data){
        console.log(data);
    }).catch(function(err){
        console.log(err);
    });

License

Licensed under the MIT license.