基于 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://codercto.com/soft/d/3317.html

编写高质量代码:改善Python程序的91个建议

编写高质量代码:改善Python程序的91个建议

张颖、赖勇浩 / 机械工业出版社 / 2014-6 / 59.00元

在通往“Python技术殿堂”的路上,本书将为你编写健壮、优雅、高质量的Python代码提供切实帮助!内容全部由Python编码的最佳实践组成,从基本原则、惯用法、语法、库、设计模式、内部机制、开发工具和性能优化8个方面深入探讨了编写高质量Python代码的技巧与禁忌,一共总结出91条宝贵的建议。每条建议对应Python程序员可能会遇到的一个问题。本书不仅以建议的方式从正反两方面给出了被实践证明为......一起来看看 《编写高质量代码:改善Python程序的91个建议》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

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

html转js在线工具