apache / dubbo-js Goto Github PK
View Code? Open in Web Editor NEWThe Typescript implementation of Apache Dubbo. An RPC and microservice framework for Node.js and Web development.
Home Page: https://dubbo.apache.org/
License: Apache License 2.0
The Typescript implementation of Apache Dubbo. An RPC and microservice framework for Node.js and Web development.
Home Page: https://dubbo.apache.org/
License: Apache License 2.0
你好:
我一个服务注册在两个不同的zookeeper,想通过dubbo2.js 调用这两个不同注册中心上的服务,发现只能调用同一个注册中心上的服务。
以下为实现:
const {Dubbo, java, TDubboCallResult} = require('dubbo2.js');
const {dubboInvoke,invoker} = require('dubbo-invoker');
const app = require('http');
//创建dubbo对象
var dubbo = new Dubbo({
application: {name: 'dubbo-node-consumer'},
//zookeeper address
register: '127.0.0.1:2182',
dubboVersion: '2.0.10',
interfaces: ['com.sitech.hsf.Interface.ServerA'],
});
const demoProvider = dubbo.proxyService({
dubboInterface: 'com.sitech.hsf.Interface.ServerA',
version: '2.0.0',
timeout:10,
group:'',
methods: {
sayHello(name) {
return [java.String(name)];
},
},
});
var dubbo2 = new Dubbo({
application: {name: 'dubbo-node-consumer1'},
//zookeeper address
register: '127.0.0.1:2181',
dubboVersion: '2.0.10',
interfaces: ['com.sitech.hsf.Interface.ServerA'],
});
const demoProvider2 = dubbo2.proxyService({
dubboInterface: 'com.sitech.hsf.Interface.ServerA',
version: '2.0.0',
timeout:10,
group:'',
methods: {
sayHello(name) {
return [java.String(name)];
},
},
});
(async () => {
await dubbo.ready();
await dubbo2.ready();
console.log('dubbo ready over...');
})();
(async () => {
await dubbo.ready();
await dubbo2.ready();
console.log('dubbo ready over...');
})();
app.createServer(async (req, res) => {
const result1 = await demoProvider.sayHello("node");
const result2 = await demoProvider2.sayHello("node");
const result3 = await demoProvider2.sayHello("node");
const result4 = await demoProvider.sayHello("node");
console.log('end->',result1,result2,result3,result4);
res.end(result.res);
}).listen(8080);
如题,谢谢。
我的dubbo.json配置文件为:
{
"output": "./src",
"entryJarPath": "./java/dubbo-demo/qifutong-api/target/qifu-labourer-client-1.1.6-SNAPSHOT.jar",
"libDirPath": "./java/dubbo-demo/qifutong-api/target/lib/"
}
其中的jar包和依赖包都是有的。
然后npm install interpret-dubbo2js
运行interpret -c dubbo.json
运行结果为:
Output at: C:\Users\ADMINI~1\AppData\Local\Temp\jexpose2045571442071863293
elapsed: 81.317s
read jar ast file C:\Users\ADMINI~1\AppData\Local\Temp\jexpose2045571442071863293\output\deflated.json
Translation completed
第一个是包没有输出到我指定的路径,其二是输出的文件中output文件夹下只有一个deflated文件,里边内容为:
{
"classes":{},
"providers":[]
}
请问下这是什么原因呢?
hi
我现在egg工程中,service内new Dubbo,用proxyService注册方法,然后调用。
第一次能成功,同一个接口调用第二次就会超时。
如果重启工程又能进行一次调用,第二次超时。有碰到过这种情况的吗?
代码大致如下:
`
import { Context, Service } from 'egg';
import { Dubbo, java, TDubboCallResult, Context as DubboContext } from 'dubbo2.js';
export default class MyService extends Service {
constructor(ctx: Context) {
super(ctx);
}
/**
* 新建模板活动
*/
public async createActivity(arg1, arg2) {
const { ctx } = this;
const { dubboGroup, dubboBase } = ctx.app.config;
// 创建dubbo实例
const dubbo = new Dubbo({
...dubboBase.myConfig,
dubboInvokeTimeout: 30,
service: { myApiService: this.myApiService },
});
dubbo.subscribe({
onTrace: (msg) => {
this.logger.info(msg);
},
});
const doSometing = dubbo.service['myApiService'].doSometing;
const result = await doSometing(arg1, arg2);
if (result.err) {
this.logger.error(result.err);
this.ctx.throw('dubbo服务出错,请联系管理员');
}
return result.res;
}
private myApiService = (dubbo) => {
const { ctx } = this;
const { dubboGroup, dubboBase } = ctx.app.config;
return dubbo.proxyService({
dubboInterface: 'my.dubbo.interface',
version: '0.0.0',
group: dubboGroup.myConfig,
methods: {
doSometing(arg1, arg2) {
return [
java.String(arg1),
java.String(arg2)
];
},
},
});
}
}
`
目前翻译会把私有变量也翻译出来如下边的logger, 而这个变量在java端是内容的,没有任务语义,应该过滤
import {Logger} from './../../../../../../org/slf4j/Logger';
import java from 'js-to-java';
export interface IUserUpdatePwdRequest {
serialVersionUID?: number;
pwdStrength?: string;
securityType?: string;
oldPassword?: string;
logger?: Logger;
systemType?: string;
adminId?: string;
newPassword?: string;
operationType?: string;
userId?: string;
token?: string;
}
export class UserUpdatePwdRequest {
constructor(params: IUserUpdatePwdRequest) {
this.serialVersionUID = params.serialVersionUID;
this.pwdStrength = params.pwdStrength;
this.securityType = params.securityType;
this.oldPassword = params.oldPassword;
this.logger = params.logger;
this.systemType = params.systemType;
this.adminId = params.adminId;
this.newPassword = params.newPassword;
this.operationType = params.operationType;
this.userId = params.userId;
this.token = params.token;
}
serialVersionUID?: number;
pwdStrength?: string;
securityType?: string;
oldPassword?: string;
logger?: Logger;
systemType?: string;
adminId?: string;
newPassword?: string;
operationType?: string;
userId?: string;
token?: string;
__fields2java() {
return {
$class: 'com.qianmi.usercenter.api.bo.security.UserUpdatePwdRequest',
$: {
serialVersionUID: java.Long(this.serialVersionUID),
pwdStrength: java.String(this.pwdStrength),
securityType: java.String(this.securityType),
oldPassword: java.String(this.oldPassword),
logger: this.logger['__fields2java']
? this.logger['__fields2java']()
: this.logger,
systemType: java.String(this.systemType),
adminId: java.String(this.adminId),
newPassword: java.String(this.newPassword),
operationType: java.String(this.operationType),
userId: java.String(this.userId),
token: java.String(this.token),
},
};
}
}
//generate by interpret-cli dubbo2.js
目前只支持随机算法,后面支持更多负载均衡的算法。
实际测试,随机算法已经比较均衡。
你没有实现呀,有思路吗?
您好!
我研究了一下源码,没有发现有失败重试的功能,是不没有实现或者我没有找到对应的代码,是否可以扩展容错的一些机制
如题,文档看过没有明白应该如何使用,可能我被自己的思路所限制了,可以请教下如何使用吗?
我是一名 Node.js 开发,现有的解决方案是自己实现了一个 node-dubbo-client 的包,通过 Java 提供的服务名(com.alibaba.dubbo.demo.DemoProvider)从 zk 获取 Dubbo 服务的地址与端口,然后通过 Java 提供的函数名(getUserInfo)调用到真实的服务,数据传递使用的是 JSON,然后 Java 那边将 JSON 再反序列化成 Java 的数据类型,然后再通过将结果转成 JSON 返回给我。
基于上述的流程,感觉被自己的思路限制了,看着 dubbo2.js 的文档和示例,依旧没有看懂我应该怎么做,服务名和方法名应该写在哪里,参数应该如何传递。
类似最下面的代码,如果人工去编写,成本较高,最好能通过JAR包直接生成,这个功能点有没有规划去落地?
/Create the service to be injected
import {Dubbo} from 'dubbo2.js';
const demoProvider = dubbo =>
dubbo.proxyService({
dubboInterface: 'com.alibaba.dubbo.demo.DemoProvider',
version: '1.0.0',
methods: {
sayHello(name) {
return [java.String(name)];
},
echo() {},
test() {},
getUserInfo() {
return [
java.combine('com.alibaba.dubbo.demo.UserRequest', {
id: 1,
name: 'nodejs',
email: '[email protected]',
}),
];
},
},
});
provider自己封装了protocol协议,怎么在consumer端去指定协议?
@hufeng 上下文请移步 QianmiOpen/dubbo-node-client#15
期待你们的回复,非常感谢!
在开发过程中 调用 com.qianmi.mc.api.buyer.BuyerActivityQueryProvider 出现异常.跟踪如下:
dubbo 启动时,providerurl信息,可以看出BuyerActivityQueryProvider 并没有相应的provider
登陆 zookeeper 查看 ,确实没有
查看 dubbo源代码 . 在调用接口,如果没找到相应的SocketWorker,则会报:Could not find any agent worker
private _handleDubboInvoke(requestId: number) {
//get request context
const ctx = queue.requestQueue.get(requestId);
//get socket agent list
const agentAddrList = this._zkClient.getAgentAddrList(ctx);
log('agentAddrSet-> %O', agentAddrList);
const worker = this._serverAgent.getAvailableSocketWorker(agentAddrList);
//if could not find any available socket agent worker
if (!worker) {
const {requestId, dubboInterface, version, group} = ctx;
const msg = `requestId#${requestId}:Could not find any agent worker with ${dubboInterface}#${version}#${group} agentList: ${agentAddrList.join(
',',
)}`;
const err = new ScheduleError(msg);
this._handleFailed(requestId, err);
log(err);
traceErr(err);
return;
}
ctx.invokeHost = worker.host;
ctx.invokePort = worker.port;
const providerProps = this._zkClient.getDubboServiceProp(ctx);
queue.consume(ctx.requestId, worker, providerProps);
}
例:
router.get('/user', async ctx => { const {res, err} = await dubbo.service.demoProvider.getUserInfo(); ctx.body = res || err.message; });
node端调用rpc服务,service端抛出异常err信息带打印信息不是标准的json对象,不知道问题出在哪里?求指教!!
你好:
我现在需要初始化多个dubbo 但是初始化或后始终调用的是一个zk上的服务。
如下为编写的代码。
如果我想通过监听事件动态调用,注册在不同zk上的服务,会出现调用不到我想要的调用的服务。
`const {Dubbo, java, TDubboCallResult} = require('dubbo2.js');
const {dubboInvoke,invoker} = require('dubbo-invoker');
const app = require('http');
var url = require('url');
var events = require('events');
var emitor = new events.EventEmitter();
var opt = [{
application: {name: 'dubbo-node-consumerA'},
register: '127.0.0.1:2182',
dubboVersion: '2.0.10',
interfaces: ['com.sitech.hsf.Interface.ServerA'],
},{
application: {name: 'dubbo-node-consumerB'},
register: '127.0.0.1:2181',
dubboVersion: '2.0.10',
interfaces: ['com.sitech.hsf.Interface.ServerA'],
}];
var proxy = {
dubboInterface: 'com.sitech.hsf.Interface.ServerA',
version: '2.0.0',
timeout:10,
group:'',
methods: {
sayHello(name) {
return [java.String(name)];
},
},
};
var dubbo = new Dubbo(opt[0]);
var dubbo1 = new Dubbo(opt[1]);
var proxyProvider = dubbo.proxyService(proxy);
var proxyProvider1 = dubbo1.proxyService(proxy);
//始终调用到dubbo1注册的zk的服务。
emitor.on('input',function (res,pid){
var result = async (id) => {
var result = await proxyProvider'sayHello';
var result1 = await proxyProvider1'sayHello';
console.log('result',result);
console.log('result',result1);
return result;
};
result(pid).then((data) => {res.end(result1.res);} );
});
app.createServer(function(req, res) {
const path = url.parse(req.url).pathname;
var params = url.parse(req.url,true).query;
if(path == '/dubbo'){
emitor.emit('input',res,params.id);
}
}).listen(9090);`
能不能做的像java的JMX一样很很直观的展示。
HI,我想在dubbo调用时传递userid等值,但不想在每个接口都设个变量。请问能否通过上下文的方式传递值?谢谢~
Is your feature request related to a problem? Please describe.
在这里进行 重连 的时候,我们是否应该像这里描述的一样 nodejs/node#5757 (comment) 增加一个超时的机制,否则,代码可能需要增加类似下面的逻辑
if (this._retry > 0) {
if (IS_RECONNECTING) return;
// reconnecting...
} else {
...
}
Describe the solution you'd like
A clear and concise description of what you want to happen.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
第一次使用 Dubbo,以下是我对本项目的理解,如有错误,望不吝赐教。
其中关于第二点是我最困惑的,是我没找到 Node 发布服务的方式,还是 Dubbo 只能通过 JAVA 进行服务发布。
//创建dubbo对象
const dubbo = new Dubbo({
application: {name: 'node-dubbo'},
//zookeeper address
register: 'localhost:2181',
dubboVersion: '2.0.0',
interfaces: ['com.alibaba.dubbo.demo.DemoService'],
});
在目前的dubbo创建对象中,需要传递interfaces参数,原因是zookeeper的注册中心里面可能包含了大量的dubbo接口的信息,如果都去订阅,在zookeeper发生变化的时候,就会大量的watch,所有通过传递这个参数来设置我们需要关心和订阅的接口。
能不能在保证相同的体验下,内部获取这些参数。可能的思路,比如proxyService异步将代理服务的接口名搜集起来,告诉zookeeper。
例如 :var consumers = path.join('/dubbo', provider, 'consumers'); 在windows上面返回的是 \ 而不是 /
provider
public interface PaymentProvider{
PayResultBO guaranteePayment(PaymentBO paymentBO, PaymentMethod paymentMethod, String realPayeeUserId, EnumTradeChannel enumTradeChannel)
throws BaseException;
}
父类
public abstract class PaymentMethod extends BaseBean implements Cloneable {
}
子类
public class PaymentMethodOLP extends PaymentMethod {
}
以上代码,
期望的是Java类转换成node后,依赖包中包含PaymentProvider、PaymentMethod、PaymentMethodOLP等文件。
结果转换成node后只包含了PaymentProvider和PaymentMethod。
PaymentMethodOLP文件丢失了
如图,egg配合dubbo2.js通过zk调用dubbo的时候一直报这个错
有没有大佬知道的帮忙解决下,开启了 DEBUG=dubbo* 也没有找出问题所在
@hufeng
能否支持jeager分布式跟踪(koa-await-breakpoint-jaege)
https://www.bookstack.cn/read/node-in-debugging/6.4OpenTracingJaeger.md
const enum feature:
for example:
const enum Status {
PADDING = "PADDING",
READY = "READY",
FAILD = "FAILD"
}
function test() {
const currentStatus = Status.PADDING;
}
function test() {
var currentStatus = "PADDING" /* PADDING */;
}
enum Status {
PADDING = "PADDING",
READY = "READY",
FAILD = "FAILD"
}
function test() {
const currentStatus = Status.PADDING;
}
var Status;
(function (Status) {
Status["PADDING"] = "PADDING";
Status["READY"] = "READY";
Status["FAILD"] = "FAILD";
})(Status || (Status = {}));
function test() {
var currentStatus = Status.PADDING;
}
因为我的电脑用户名被设置了中文,导致路径乱码,求处理一下这个路径编码问题!!,而且生成的ts文件里面的引用路径也有问题
伟大的创造者您好!
请问dubbo2的调用负载均衡方式是何种方式,是否支持负载均衡的动态配置。谢谢!
HI,
现在遇到一个情况,我需要连接2个application。如果我对每个application new Dubbo的话,就破坏了单例模式,导致超时。
请问现在是否支持连接同一register上的不同application?
不知有没有实践过 json-rpc
的调用方式,关于 rt 以及并发上,能否接受,个人觉得 json-rpc 更适合跨语言调用
你好:
err: Error: uuid: invoke com.sitech.hsf.Interface.ServerA#sayHello was error,
这个错是什么意思
hi
我在egg新开工程,尝试调用线上已存在的dubbo服务。一直报错,不知道是什么原因。
Fail to decode request due to: RpcInvocation [methodName=xxx, parameterTypes=null, arguments=null, attachments={path=yyy, input=199, dubbo=2.8.4, version=}]
dubboVersion: 2.8.4
promise
async、await
在某个版本内部实现中,是有retry的机制
在内部讨论下,在一些场景下接口调用不是幂等的,暂时舍弃这部分功能。
作为opensource就完善这个功能。
在Context记录retry次数,然后在scheduler中timeoutError后者onClose中尝试重试机制。
1.例如:
package com.example.service;
import com.example.dto.User;
public interface UserServiceProvider {
public String getUserName();
public User getUser(User user);
}
2.例如:
package com.example.service;
import com.example.dto.User;
public interface UserService {
public String getUserName();
public User getUser(User user);
}
1是可以生成ts文件,2就是不可以生成。这是哪里可以通过参数设置吗 ?
有没有nodejs作为消费者的例子
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.