omnip620 / node-zookeeper-dubbo

A middleware helps node to communicate dubbo by using its default protocol, which is registered in zookeeper
300 stars 80 forks source link

Fail to decode request due to: RpcInvocation #50

Closed chua1989 closed 7 years ago

chua1989 commented 7 years ago

完整的错误是: Fail to decode request due to: RpcInvocation[methodName=getAvailableQuickPayBankMap, parameterTypes=[], arguments=null, attachments={dubbo=2.8.4, input=220, path=com.njq.nongfadai.service.IBankService, version=1.0.0}

代码:

const nzd = require('node-zookeeper-dubbo');
const app = require('express')();
const opt = {
  application: {
    name: 'nongfadai-dubbo-provider'
  },
  register: '10.1.60.23:2181',
  dubboVer: '2.8.4',
  root: 'dubbo',
  dependencies: {
    IBankService: {
      interface: 'com.njq.nongfadai.service.IBankService',
      version: '1.0.0',
      timeout: 30000
    }
  }
};
//转换类型使用的例子:https://github.com/node-modules/js-to-java
opt.java = require('js-to-java');

const Dubbo = new nzd(opt);

//无参数的例子
app.get('/IBankService/getAvailableQuickPayBankMap', (req, res) => {
  Dubbo.IBankService
    .getAvailableQuickPayBankMap()
    .then(data => {
      res.send(data);
    })
    .catch(err => {
      res.send(err);
    });
});

app.listen(9090);

这个接口不需要参数http://localhost:9090/IBankService/getAvailableQuickPayBankMap

使用的版本: node-zookeeper-dubbo@2.2.1 dubbox 2.8.4 node 6.10.2

chua1989 commented 7 years ago

跟踪源码是因为encode.js中下面这段代码导致的,去掉即可

var ver = this._opt._dver || '2.5.3.6';
if(ver.startsWith('2.8')){
   body.write(-1);  //for dubbox 2.8.X
}
omnip620 commented 7 years ago

迷之诡异啊 这段代码是之前有个朋友提交的 目的是为了能够在2.8.4也就是dubbox使用 你这边解决方案 就是把这段去掉 然后2.8.4就能通信成功?

chua1989 commented 7 years ago

是的

harryhan1989 commented 5 years ago

项目需求nodejs连接dubbo接口,找到node-zookeeper-dubbo很不错,但是复杂java对象却很难开发。网上也没搜到这方面的工具,索性自己写了个,经过多次调试试错,实现了普通json自动转换为dubbo可识别的java序列化对象,可支持java实体类内嵌实体类及内嵌List这种转化,简单高效,现在实现的比较简单,就是个工具类,有兴趣的同学欢迎包装为nodejs通用插件或eggjs插件:https://github.com/harryhan1989/json-to-java

harryhan1989 commented 5 years ago

你这个也是对象转换不对造成的,java dubbo识别不了