# wrpc

> Simple node RPC framework.

Latest version **0.0.9** (published 2018-06-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install wrpc
pnpm add wrpc
yarn add wrpc
bun add wrpc
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.9 |
| Published | 2018-06-26 |
| First published | 2018-04-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 176.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | lizhekang |
| Maintainers | lizhekang |

## Links

- npm: https://www.npmjs.com/package/wrpc
- Repository: https://github.com/lizhekang/wrpc
- Homepage: https://github.com/lizhekang/wrpc#readme
- Issues: https://github.com/lizhekang/wrpc/issues
- npm.io page: https://npm.io/package/wrpc

## Recent versions

- 0.0.9 (latest) — 2018-06-26
- 0.0.8 — 2018-06-26
- 0.0.7 — 2018-06-26
- 0.0.6 — 2018-06-24
- 0.0.5 — 2018-05-19
- 0.0.4 — 2018-04-30
- 0.0.3 — 2018-04-30
- 0.0.2 — 2018-04-30
- 0.0.1 — 2018-04-30

## README

# wrpc

简单的远程函数调用框架。

## log

- v0.0.1 基本的远程调用能力。
- v0.0.2 客户端掉线重连能力。
- v0.0.3 添加错误码字段。

## 使用

调用方：

```javascript
let rpc = require('wrpc');

let funcDef = {
    add: (a, b) => {return a+b;}
};

let cfg = {
  "type": "master", //本地
  "name": "master",
  "server": {
    "ip": "127.0.0.1",
    "port": 10001
  }
};

let m = new rpc(funcDef, cfg);
m.init();

//执行远程调用
m.call('add', [1, 2], (res) => {
    console.log(res);
}, (err) => {
    console.log(err);
})
```

被调用方（远程）：


```javascript
let rpc = require('wrpc');

let funcDef = {
    add: (a, b) => {return a+b;}
};

let cfg = {
  "type": "slave",  //远程
  "name": "worker1",
  "server": {
    "ip": "127.0.0.1",
    "port": 10001
  }
};

let s = new rpc(funcDef, cfg);
s.init();
```

## 配置说明

```json

{
  "type": "slave",
  "name": "worker1",
  "server": {
    "ip": "127.0.0.1",
    "port": 10001,
    "retry": true,
    "maxRetryTimes": 10
  }
}

```

| 字段 | 类型 | 必须 | 说明 |
| ---- | ----- | ---- | ---- |
| type | string | 是 | master 或 slave，用于表示调用方与被调用方 |
| name | string | 是 | 服务名 |
| server | object | 是 | 服务配置 |
| server --> ip | string | 是 | 服务地址 |
| server --> port | number | 是 | 服务端口 |
| server --> retry | boolean | 否 | 是否尝试重连，只对于被调用方服务生效 |
| server --> maxRetryTimes | number | 否 | 最大重试次数，只对于开启了尝试重连的被调用方服务生效 |

---
_Source: https://npm.io/package/wrpc · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
