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

node-dubbo-client

v1.1.1

Published

node dubbo consumer/provider

Downloads

42

Readme

node-dubbo-client

Build Status codecov

NPM

Installation

npm install --save node-dubbo-client

Example

consumer

const dubbo = require('node-dubbo-client');

dubbo.config({});

dubbo
  .consumer
  .getService({ service: 'test.service', group: 'test', version: '1.0.0' })
  .call('testMethod', ['params'])
  .then((result) => console.log(result))
  .catch((err) => console.error(err));

provider

const dubbo = require('node-dubbo-client');

dubbo.config({});

dubbo
  .provider
  .init({ service: 'node.testService', group: 'node', version: '1.0.0' })
  .addMethods({ 
    test: (...args) => Promise.resolve({ result: 'hello world!' }), 
  })
  .listen(3000);

Document

dubbo.init(options:object):Promise<void>

初始化zookeeper连接.

订阅者模式下, service调用会一直阻塞到zookeeper连接创建.

发布者模式下, 本地http server启动后再连接到zookeeper, 并发布服务.

如果两个模式共用, 以发布者模式为准.

options

  • description object - 应用描述
    • application string - 当前应用名称
    • application.version string - 当前应用的版本
    • dubbo string - dubbo版本
    • pid number - 进程Id
  • dubbo object - service配置
    • timeout number (default: 45 * 1000) - 服务提供者调用超时时间
    • enableRetry boolean (default: true) - 自动重试,服务提供者返回ECONNREFUSED,下线该提供者并重试
  • registry object
    • url string (required)
    • options object - node-zookeeper-client options
      • sessionTimeout number (default: 30 * 1000)
      • spinDelay number (default: 1000)
      • retries number (default: 0)
  • loadBalance string (default: 'round') - 订阅者调用的负载方式(round/random)
  • debug boolean (default: false) - 是否输出zookeeper推送的消息.

dubbo.dispose():Promise<void>

订阅者模式下, 只关闭zookeeper连接.

发布者模式下,会依次进行以下操作:

  1. 从zookeeper上移除当前服务节点;
  2. 关闭zookeeper连接;
  3. 关闭http服务器.

dubbo.onLog(calbak:function(msg:string)):void

日志输出, 如果给予回调函数, 默认使用debug 输出日志.

  • options.debug=true, it will print zookeeper listener result.

dubbo.consumer

getService(serviceInfo:object):serviceObject

  • serviceInfo object
    • service string (required) 服务的namespace
    • group string (required)
    • version string (required)

serviceObject.call(methodName:string, data:Array<*>)

// 后端提供者
public String testMethod(int a, int b, int c);
// consumer 方法调用
const service = dubbo.consumer.getService({});
service
  .call('testMethod',[1, 2, 3])
  .then((str) => {})
  .catch(() => {});

dubbo.provider

init(serviceInfo:object):Provider

provider基本信息声明.

Provider.addMethods(functions:object):Provider

批量添加provider方法

provider.addMethods({
  method1: (a, b, c) => {
    return 'something';
  },
});

Provider.addMethod(name:string, handler:function(...params:*):*):Provider

添加单个provider方法

Provider.listen(port:number):Promise

启动provider的http服务器.该方法应该在provider配置完成之后调用

Provider.configServer(serverOpts:object):Provider

  • serverOpts object

配置http服务, 目前只提供raw-body的配置项.