nodejs connect dubbo by default protocol in zookeeper
There are a lot of improvements in v2.0
if you want coexistence between different versions,use niv.
dubbo service version
zookeeper conn url
the service you need
dubbo version
first you need to init the service so that invoke the consumers in zk
app.js
var service=require('node-zookeeper-dubbo');
new Service({
env:'test',
conn:'127.0.0.1:2180',
services: require('./dubbo/services')
})
/dubbo/services.js
'use strict';
module.exports = {
Foo: 'com.customer.FooService',
Bar: 'com.customer.BarService'
};
in you business code, service.js
var Service=require('node-zookeeper-dubbo');
var opt={
env:'test', // dubbo service version
gruop:'dubbo', // dubbo group default by 'dubbo',optional
conn:'127.0.0.1:2180', // zookeeper url
path:'com.customer.Service', // service url
version:'2.3.4.5' // dubbo version
}
var method="getUserByID";
var arg1={$class:'int',$:123}
var args=[arg1];
var service = new Service(opt);
service.excute(method,args,function(err,data){
if(err){
console.log(err);
return;
}
console.log(data)
})
or
service
.excute(method,args)
.then(function(data){
console.log(data);
})
.catch(function(err) {
console.log(err);
})
});
you can use js-to-java
var arg1={$class:'int',$:123};
//equivalent
var arg1=java('int',123);
Default the zookeeper connection is keep-alive,you can call service.zoo.close()
to close the connect;
There are a lot of non-functional requirements need to be satisfied, but time is hard, so pls patience, we'll scare you.