dependencies:自定義若干接口名java
1,本身建立http請求node
2,http請求裏調用dubbo方法(注意參數的定義格式和要傳入java定義參數的model類名)git
node-dubbo.jsgithub
const ZookeeperDubbo = require('node-zookeeper-dubbo'); const app=require('express')(); var java = require('js-to-java'); const Dubbo = new ZookeeperDubbo({ application: { name: 'provider' }, registry: '172.29.8.100:2181', dubboVer: '2.8.4', root: 'dubbo', dependencies: { IUserApi: { interface: 'com.xxx.api', timeout: 6000, methodSignature: { getUserLists : (Obj) => [{$class: 'com.xxx.model',$:Obj}], } } } }) app.get('/foo',(req,res)=>{ const customerObj = { $class: 'com.xxx.model', $: { userName: java.String('test'), uin: java.String('1000000000000') } }; Dubbo.IUserApi .getUserLists(customerObj) .then(data=> { console.log('data---------'+data); res.send(data) }) .catch(err=>{ console.log('err---------'+err); res.send(err) }) }) app.listen(9090)
package.jsonexpress
{ "name": "dubbo", "version": "1.0.0", "description": "", "main": "node-dubbo.js", "dependencies": { "express": "^4.16.4", "js-to-java": "^2.6.1", "node-zookeeper-dubbo": "^3.0.15" }, "devDependencies": {}, "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC" }
1,node node-dubbo.js(會提示初始化成功 Dubbo service init done)
2,瀏覽器運行本身建立的接口(成功會返回dubbo對應接口的方法的返回值)
http://localhost:9090/fooapache
1,安裝node-zookeeper-dubbo的3.0.0及如下版本會報錯,初始化不成功json
2,Fail to decode request due to: RpcInvocation
註釋掉node-zookeeper-dubbo包中libs下的encode.js文件中如下代碼(針對dubbox的東西,但後端用的是dubbo)後端
// if (ver.startsWith("2.8")) { // body.write(-1); //for dubbox 2.8.X // }
https://github.com/omnip620/n...
https://github.com/omnip620/n...api
dubbo-js
https://github.com/apache/dub...瀏覽器