Comments (8)
目前dubbo2.js仅仅支持原生的dubbo协议(dubbo header + hessian body)
红线部分就是对应的你迷惑的服务名和方法名字地方
这么地方就是定义的接口名称,方法名称。
参考demo和单元测试
抱歉文档还是需要改进 可以一起来维护 @DuanPengfei
from dubbo-js.
看到引入服务是通过引入本地文件的方式,如果我要请求的服务已经注册到 zk 上了,比如注册到了 /dubbo/providers/com.alibaba.dubbo.demo.DemoProvider 这个路径了,原本的方案是请求 zk 这个路径获取真实的 Dubbo 服务地址,如果是用 dubbo2.js 这样的我要怎么写呢?
from dubbo-js.
import {Dubbo} from 'dubbo2.js';
//封装js版本DemoProvider
//通常这个部分是通过我们写的一个工具自动根据jar生成
const demoProvider = dubbo =>
dubbo.proxyService({
//调用的接口名称
dubboInterface: 'com.alibaba.dubbo.demo.DemoProvider',
//接口中暴露给外面的方法
methods: {
//方法名称
sayHello(name /*参数*/) {
//hessian化参数,返回一个数组对name进行包装
return [java.String(name)];
},
echo() {},
test() {},
getUserInfo() {
return [
java.combine('com.alibaba.dubbo.demo.UserRequest', {
id: 1,
name: 'nodejs',
email: '[email protected]',
}),
];
},
},
});
//将该service合入dubbo对象构造函数的service对象中
//这样如果用typescript可以获取完美的代码提示
const service = {
demoProvider,
};
const dubbo = new Dubbo<typeof service>({
// ....other parameters
service,
});
//invoke
(async () => {
const {res, err} = await dubbo.service.demoProvider.sayHello('node world!');
console.log(err, res);
})();
from dubbo-js.
不知道是不是我理解的问题哦,看这个流程,不是直接调用 Java 提供的服务,而是对应 Java 提供的服务要封装一个自己的服务,比如 com.alibaba.dubbo.demo.DemoProvider
,自己的服务里提供函数 getUserInfo
,然后这个函数中再去请求 Java 提供的服务,比如 com.alibaba.dubbo.demo.UserRequest
?
from dubbo-js.
@DuanPengfei ,可以这样理解的^_^, 核心的问题是nodejs这边需要处理dubbo调用的协议以及序列化和反序列化,我们自己写的js版本的DemoProvider实际上就是在做一个序列化的过程。
from dubbo-js.
了解了,怪不得我一直都没有看明白,按照我现有的方式,序列化和反序列化是处于 Node.js 和 Java 的中间一层,Node.js 这边只要从 zk 获取到 Dubbo 服务的 IP 和 port 就可以直接向上面发送 JSON 格式的数据了,Java 前面有一层序列化和反序列化。谢谢回复了,我先尝试下 dubbo2.js。
from dubbo-js.
@DuanPengfei 有问题一起讨论 ^_^ 是的 后面我会添加一个json-rpc之类的协议 就可以像您说的直接发送json格式的数据,目前dubbo2.js发送的是hessian格式的数据。
from dubbo-js.
👌
from dubbo-js.
Related Issues (20)
- Improve documentation (Node aspect) HOT 2
- Improve documentation (Node aspect) HOT 1
- Improve documentation (Web aspect) HOT 3
- Improve documentation (Web aspect) HOT 2
- Improve documentation (Web aspect) HOT 2
- Improve documentation (Web aspect) HOT 1
- Improve documentation (Web aspect) HOT 2
- I'll handle the items
- Implement Load Balance HOT 1
- Implement Traffic Routing HOT 1
- Implement Service Discovery HOT 1
- Implement Filter HOT 1
- Implement Metrics HOT 3
- Implement Tracing HOT 1
- [API Bug]: dubboNodeAdapter HOT 1
- 请问支持服务注册发现、负载均衡等服务治理能力吗? HOT 2
- 麻烦问下,这个 protoc 命令是怎么来的? 为什么我的 node_module/.bin 下面没有?
- 请问可以利用java dubbo3+版本泛化调用至【Apache Dubbo-js 4.0.0 released】提供的dubbo接口吗? HOT 3
- dubbo-node has type dependency problem
- Missing property type declaration
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dubbo-js.