node调用dubbo,使用工具库:apache-dubbo-js
代码地址:https://github.com/apache/dubbo-js
npm安装
npm install apache-dubbo-js
import { Dubbo } from 'dubbo-js';
const demoProvider = dubbo =>
dubbo.proxyService({
// 包路径
dubboInterface: 'org.apache.dubbo.demo.DemoProvider',
// 包版本
version: '1.0.0',
// 包接口
methods: {
sayHello(name, age) {
// 参数转java类型
return [java.String(name), java.Integer(name)];
},
getUserInfo() {
// DTO参数
return [
java.combine('org.apache.dubbo.demo.DTO', {
id: 1,
name: 'nodejs',
email: 'node@test.com',
}),
];
},
},
});
module.exports = {
demoProvider,
};
import { Dubbo } from 'dubbo-js';
// 引入service
import service from './service';
const dubbo = new Dubbo({
application: { name: 'dubbo-js' },
// zookeeper 地址
register: 'localhost:2181',
service,
});
返回的是promise
dubbo.service.DemoProvider.sayHello('node', 23);
dubbo.service.DemoProvider.getUserInfo())