0.3.10 • Published 6 months ago

@cloudpss/rpc v0.3.10

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

RPC 服务

npm

用于 CloudPSS 内部微服务的 RPC 框架,简单封装了 Apache Thrift。

pnpm add @cloudpss/rpc

使用

生成接口文件

  • 创建 thrift IDL 文件(如:rpc/my-service.thrift
  • 运行 thrift 命令生成 JS/TS 接口
    pnpm thrift -r --gen js:ts,es6,node -out ./src/thrift

服务端

import * as MyService from './thrift/MyService';
import { createServer } from '@cloudpss/rpc';

const service = createServer();
service.route('my-service', MyService, {
  // implementation
  add(a, b) {
    return a + b;
  },
});
service.listen(Number(process.env.PORT || 4000));

客户端

import * as MyService from './thrift/MyService';
import { createClient } from '@cloudpss/rpc';

const client = createClient({
  host: 'localhost',
  port: Number(process.env.PORT || 4000),
});
const service = client.get('my-service', MyService);
// ...
// use service here
// ...
const result = await service.add(1, 2);

client.destroy();

开发

初始化本地环境

pnpm install

调试

pnpm start

发布

pnpm version
npm publish
0.3.9

6 months ago

0.3.10

6 months ago

0.3.6

10 months ago

0.3.5

10 months ago

0.3.8

8 months ago

0.3.7

10 months ago

0.3.4

2 years ago

0.3.3

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.1.0-dev.7

3 years ago

0.1.0

3 years ago

0.2.1

3 years ago

0.1.0-dev.5

3 years ago

0.2.0

3 years ago

0.1.0-dev.6

3 years ago

0.1.0-dev.3

3 years ago

0.1.0-dev.4

3 years ago

0.1.0-dev.1

3 years ago

0.1.0-dev.2

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago