node-zookeeper-dubbo

中间件通过使用其在zookeeper中注册的默认协议来帮助node与dubbo通信。(A middleware helps node to communicate dubbo by using its default protocol, which is registered in zookeeper)

Github stars Tracking Chart

node-zookeeper-dubbo

nodejs通过dubbo默认协议通信

3.0版本发布,使用长连接进行通信,同时重构了大量代码,性能几乎翻倍。

用法

const nzd=require('node-zookeeper-dubbo');
const app=require('express')();
const opt={
  application:{name:'fxxk'},
  register:'www.cctv.com:2181',
  dubboVer:'2.5.3.6',
  root:'dubbo',
  dependencies:{
    Foo:{
      interface:'com.service.Foo',
      version:'LATEST',
      timeout:6000,
      group:'isis',
      methodSignature: { // optional
        findById : (id) => [ {'$class': 'java.lang.Long', '$': id} ],
        findByName : (name) => [ java.String(name) ],
      }
    },
    Bar:{
      interface:'com.service.Bar',
      version:'LATEST',
      timeout:6000,
      group:'gcd'
    }
  }
}

const Dubbo=new nzd(opt);

Dubbo.on("service:changed", (event)=>console.log(event))

const customerObj = {
  $class: 'com.xxx.XXXDTO',
  $: {
    a: 1,
    b: 'test',
    c: {$class: 'java.lang.Long', $: 123}
  }
};

app.get('/foo',(req,res)=>{
  Dubbo.Foo
    .xxMethod({'$class': 'java.lang.Long', '$': '10000000'},customerObj)
    .then(data=>res.send(data))
    .catch(err=>res.send(err))
})

app.get('/foo/findById',(req,res)=>{
  Dubbo.Foo
    .findById(10000)
    .then(data=>res.send(data))
    .catch(err=>res.send(err))
})

app.listen(9090)

注意

须等待初始化完毕才能正常使用,标志:Dubbo service init done

参数配置说明

  • application
    • name - 项目名称,必填
  • register - zookeeper服务地址,必填
  • dubboVer - dubbo版本,必填
  • root - 注册到zookeeper上的根节点名称
  • dependencies - 依赖的服务集,必填
    • Foo - 自定义名称,这里方便起见用Foo作为示例,必填
      • interface - 服务地址,必填
      • version - 注册的服务版本
      • timeout - 超时时间,默认6000
      • group - 分组
      • methodSignature - 方法签名

可以选择使用 js-to-java, 能极大提高效率。

const java = require('js-to-java');
const arg = {$class:'int',$:123};
//等同于
const arg = java('int',123);

感谢为这个项目作出过贡献的每个人,感谢为我提供思路和指导的 @caomu,感谢 js-to-java, hessian.js 的作者们。

Overview

Name With Owneromnip620/node-zookeeper-dubbo
Primary LanguageJavaScript
Program languageJavaScript (Language Count: 1)
PlatformLinux, Mac, Windows
License:
Release Count0
Created At2015-12-11 09:29:56
Pushed At2019-12-16 00:31:23
Last Commit At2019-02-13 13:44:33
Stargazers Count302
Watchers Count35
Fork Count80
Commits Count186
Has Issues Enabled
Issues Count101
Issue Open Count27
Pull Requests Count10
Pull Requests Open Count3
Pull Requests Close Count0
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private
To the top