基于 Node.js 的 RPC 客户端 dubbo2.js

码农软件 · 软件分类 · RPC/XMLRPC项目 · 2019-04-11 06:12:56

软件介绍

dubbo2.js —— nodejs 使用原生的 dubbo (dubbo head + hessian body) 协议打通了 dubbo 的 rpc 方法调用。

功能特性

  • 支持将 zookeeper 作为注册中心

  • 使用 TCP Dubbo 原生协议(Dubbo Header + Hessian Body)

  • Socket 池 (ServerAgent -> SocketPool -> SocketWorker)

  • 直接支持 Dubbo (const Dubbo = DirectlyDubbo({..}))

  • 中间件,易于扩展

  • 追踪

  • 支持 Dubbox

示例代码

import {Dubbo, java, TDubboCallResult} from 'dubbo2.js';
//定义dubbo方法类型接口
//方便代码自动提示
interface IDemoService {
  sayHello(name: string): TDubboCallResult<string>;
  echo(): TDubboCallResult<string>;
  test(): TDubboCallResult<void>;
  getUserInfo(): TDubboCallResult<{
    status: string;
    info: {id: number; name: string};
  }>;
}
//创建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对象
const demoService = dubbo.proxyService<IDemoService>({
  dubboInterface: 'com.alibaba.dubbo.demo.DemoService',
  version: '1.0.0',
  methods: {
    sayHello(name) {
      //仅仅做参数hessian化转换
      return [java.String(name)];
    },
    echo() {},
    test() {},
    getUserInfo() {
      //仅仅做参数hessian化转换
      return [
        java.combine('com.alibaba.dubbo.demo.UserRequest', {
          id: 1,
          name: 'nodejs',
          email: 'node@qianmi.com',
        }),
      ];
    },
  },
});
//main method
(async () => {
  const result1 = await demoService.sayHello('node');
  //print {err: null, res:'hello node from dubbo service'}
  const res = await demoService.echo();
  //print {err: null, res: 'pang'}
  const res = await demoService.getUserInfo();
  //status: 'ok', info: { id: '1', name: 'test' }
})();

本文地址:https://www.codercto.com/soft/d/3317.html

数据结构及应用算法教程

数据结构及应用算法教程

2011-5 / 45.00元

《数据结构及应用算法教程(修订版)》从数据类型的角度,分别讨论了四大类型的数据结构的逻辑特性、存储表示及其应用。此外,还专辟一章,以若干实例阐述以抽象数据类型为中心的程序设计方法。书中每一章后都配有适量的习题,以供读者复习提高之用。第1~9章还专门设有“解题指导与示例”一节内容,不仅给出答案,对大部分题目提供了详尽的解答注释;其中的一些算法题还给出了多种解法。书中主要算法和最后一章的实例中的全部程......一起来看看 《数据结构及应用算法教程》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

html转js在线工具
html转js在线工具

html转js在线工具