Installations
npm install dubbo
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>=4
Node Version
10.9.0
NPM Version
6.2.0
Score
70.2
Supply Chain
95.1
Quality
73.5
Maintenance
25
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (86.79%)
Shell (13.21%)
Developer
kaelzhang
Download Statistics
Total Downloads
3,609
Last Day
4
Last Week
11
Last Month
41
Last Year
286
GitHub Statistics
25 Stars
21 Commits
5 Forks
5 Watching
1 Branches
3 Contributors
Bundle Size
175.57 kB
Minified
50.19 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.1.2
Package Id
dubbo@1.1.2
Unpacked Size
24.45 kB
Size
7.90 kB
File Count
10
NPM Version
6.2.0
Node Version
10.9.0
Total Downloads
Cumulative downloads
Total Downloads
3,609
Last day
0%
4
Compared to previous day
Last week
10%
11
Compared to previous week
Last month
78.3%
41
Compared to previous month
Last year
3.6%
286
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
dubbo
node.js dubbo/dubbox client with zookeeper support via dubbo default hessian protocol.
想到这个项目基本上只给国人用,就破例稍微接地气一点,下面都写中文文档
- TCP 长连接及长连接池
- 动态的服务注册
- 内部使用队列处理 Service 注册的握手过程,调用者无需关心
Install
1$ npm install dubbo --save
Usage
1import Dubbo from 'dubbo' 2 3const dubbo = new Dubbo({ 4 application: 'my-application-name', 5 6 // Dubbo 父节点名 7 root: 'dubbo-test', 8 9 // Dubbo 的版本 10 version: '2.8.4', 11 zookeeper: { 12 host : '10.0.0.100:2181', 13 14 // node-zookeeper-client 的 createClient 方法的 options, 15 sessionTimeout: 30000, 16 spinDelay : 1000, 17 retries : 5 18 }, 19 20 // 需要注册的服务名,还可以使用 `dubbo.register` 方法来动态注册一个服务 21 services: { 22 member: { 23 interface: 'me.kael.service.memberService', 24 timeout: 6000, 25 group, 26 version 27 } 28 }, 29 30 // 1. Object 31 // 对于每一个 service,长连接池的大小 32 // 这些参数会被直接传递给 generic-pool 33 // 2. false 34 // 若不希望使用连接池,则传递 false 35 pool: { 36 max: 200, 37 min: 10, 38 maxWaitingClients: 500 39 } 40}) 41 42 43// 如果一个服务没有注册就被调用,那么会收到一个 Promise.reject 44dubbo.service('member') 45 46// `'login'` 为方法名 47// invoke 方法可以接多个参数 48.invoke('login', { 49 $class: 'me.kael.member.dto.loginDTO', 50 $: { 51 mobile: { 52 $class: 'java.lang.String', 53 $: '18800008888' 54 }, 55 password: { 56 $class: 'java.lang.String', 57 $: 'my-password' 58 } 59 } 60}) 61.then(isSuccess => { 62 console.log('is successful', isSuccess) 63}) 64 65 66// 动态注册一个服务 67dubbo.register('order', { 68 interface: 'me.kael.service.orderService' 69}) 70.service('order') 71.invoke('create', ...) 72.then(...)
new Dubbo(options)
创建一个 Dubbo
实例
options Object
- application
String
当前应用的名称 - root
String
dubbo 的父节点名 - version
String
连接的 dubbo 服务使用的 dubbo 版本 - zookeeper
Object
- host
String
zookeeper 的地址,格式为<ip>[:<port>]
,若端口没有定义,则默认端口为2181
- 其他
node-zookeeper-client
的参数,会直接传递
- host
- services
Object.<name:ServiceOptions>
需要预先注册的 services - pool
Object|false
连接池的 options,它会直接作为参数传递给generic-pool
ServiceOptions Object
- interface
- timeout
- group
- version
dubbo.register(name, serviceOptions)
注册一个 dubbo service,一个被注册过的 service,可以立即调用它的 service.invoke()
方法,dubbo
与 service 进行 providers 和 consumers 的握手的过程,会被 service 内部的队列处理好。
- name
String
- serviceOptions
ServiceOptions
Returns this
dubbo.service(name)
获取一个 service,即使一个名为 name
的 service,没有被注册过,该方法也会返回一个 Service
实例。
但是若一个 service 没有被注册过,那么在调动 service.invoke()
方法的时候,会得到一个 Promise.reject()
Returns Service
1// 若 `member` service 没有注册,仍然能够获取一个 member 实例 2const member = dubbo.service('member') 3 4member.invoke('login', arg).catch(err => { 5 // 但是当调用 invoke 的时候,会得到一个 `SERVICE_NOT_REGISTERED` 的错误 6 console.log(err.code === 'SERVICE_NOT_REGISTERED') 7 // true 8}) 9 10// 然后,我们若注册了 member 这个 service 11dubbo.register('member', { 12 interface: '...', 13 ... 14}) 15 16// 就可以使用这个 service 了 17member.invoke('login', arg) 18.then(isSuccess => { 19 console.log('is successfull:', isSuccess) 20})
service.invoke(methodName, ...args)
请求一个 service 方法。
- methodName
String
service 中的方法名,若该方法名不存在,则会得到一个Promise.reject
- args
any
方法的参数,可传递多个,这里的方法,需要是 java 风格的对象。可以手动拼,或者使用js-to-java
module.
1service.invoke('createProduct', product1, product2)
Returns Promise
License
MIT
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE-MIT:0
- Warn: project license file does not contain an FSF or OSI license.
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 1/20 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 2 are checked with a SAST tool
Score
3
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More