<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

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

          聯(lián)合創(chuàng)作 · 2023-09-23 12:26

          dubbo2.js —— nodejs 使用原生的 dubbo (dubbo head + hessian body) 協(xié)議打通了 dubbo 的 rpc 方法調(diào)用。

          功能特性

          • 支持將 zookeeper 作為注冊中心

          • 使用 TCP Dubbo 原生協(xié)議(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};
            }>;
          }
          //創(chuàng)建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) {
                //僅僅做參數(shù)hessian化轉換
                return [java.String(name)];
              },
              echo() {},
              test() {},
              getUserInfo() {
                //僅僅做參數(shù)hessian化轉換
                return [
                  java.combine('com.alibaba.dubbo.demo.UserRequest', {
                    id: 1,
                    name: 'nodejs',
                    email: '[email protected]',
                  }),
                ];
              },
            },
          });
          //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' }
          })();
          瀏覽 14
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  黄 在线 免费 | 五月天婷婷亚洲综合 | 亚洲无码久久 | 国产婷婷婷婷 | 麻豆三级片在线 |