varZD=require('zoodubbo');varzd=newZD({// config the addresses of zookeeperconn: 'localhost:2181'});// connect to zookeeperzd.connect();// get a invoker with a service pathvarinvoker=zd.getInvoker('com.demo.Service');// excute a method with parametersvarmethod='getUserByID';vararg1={$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:
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 pairsvarzd=newZD('localhost:2181,localhost:2182');// use an object to set the instance optionsvarzd=newZD({conn: 'localhost:2181,localhost:2182',dubbo: '2.5.3'});
client
The client instance created by node-zookeeper-client. To listen event such as follows:
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 .
cb(err, data) {Function} - The data is the returned value. When the cb is undefined, the function return a Promise instance.
Example
varmethod='getUserByID';vararg1={$class:'int',$:123};// use callbackinvoker.excute(method,[arg1],function(err,data){if(err){console.log(err);return;}console.log(data)});// or return a Promise instanceinvoker.excute(method,[arg1]).then(function(data){console.log(data);}).catch(function(err){console.log(err);});
Corey600/zoodubbo
zoodubbo
A Javascript module for Node.js to connect Dubbo service by node-zookeeper-client.
Features
Installation
You can install it using npm:
Example
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
client
The client instance created by node-zookeeper-client. To listen event such as follows:
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:
void close()
Close the connection of node-zookeeper-client. Equivalent to the following code:
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
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
void excute(method, args[, cb])
Arguments
Example
License
Licensed under the MIT license.