Skip to content

Commit

Permalink
🤖 TEST: Only test Node.js >= 14 (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 authored Nov 23, 2022
1 parent ef4f942 commit 590be81
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 89 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
Expand All @@ -22,7 +19,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [10, 12, 14]
node-version: [14]
os: [ubuntu-latest]

steps:
Expand All @@ -39,7 +36,7 @@ jobs:
tar xf zookeeper-3.4.6.tar.gz
mv zookeeper-3.4.6/conf/zoo_sample.cfg zookeeper-3.4.6/conf/zoo.cfg
./zookeeper-3.4.6/bin/zkServer.sh start
npm i -g npminstall@5 && npminstall
npm i
- name: Continuous Integration
run: npm run ci
Expand Down
17 changes: 17 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Ordered by date of first contribution.
# Auto-generated by 'contributors' on Mon, 07 Nov 2022 00:49:23 GMT.
# https://github.com/xingrz/node-contributors

zōng yǔ <[email protected]> (https://github.com/gxcsoccer)
zōng yǔ <[email protected]>
zl <[email protected]>
RabbitSion <[email protected]> (https://github.com/RabbitSion)
killa <[email protected]>
mansonchor.github.com <[email protected]>
兔子人开源 <[email protected]> (https://github.com/chans-open-source)
陈峰 <[email protected]>
mansonchor.github.com <[email protected]> (https://github.com/mansonchor)
fengmk2 <[email protected]> (https://github.com/fengmk2)
羊鹿 <[email protected]>
hyj1991 <[email protected]> (https://github.com/hyj1991)
mytEcust <[email protected]>
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 Ant Financial
Copyright (c) 2018-present Ant Group

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
56 changes: 26 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# sofa-rpc-node
[SOFARPC](https://github.com/alipay/sofa-rpc) Nodejs 实现版本

[SOFARPC](https://github.com/sofastack/sofa-rpc) Nodejs 实现版本

[![NPM version][npm-image]][npm-url]
[![Node.js CI](https://github.com/sofastack/sofa-rpc-node/actions/workflows/nodejs.yml/badge.svg)](https://github.com/sofastack/sofa-rpc-node/actions/workflows/nodejs.yml)
Expand All @@ -8,16 +9,14 @@

[npm-image]: https://img.shields.io/npm/v/sofa-rpc-node.svg?style=flat-square
[npm-url]: https://npmjs.org/package/sofa-rpc-node
[codecov-image]: https://codecov.io/gh/alipay/sofa-rpc-node/branch/master/graph/badge.svg
[codecov-url]: https://codecov.io/gh/alipay/sofa-rpc-node
[snyk-image]: https://snyk.io/test/npm/sofa-rpc-node/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/sofa-rpc-node
[download-image]: https://img.shields.io/npm/dm/sofa-rpc-node.svg?style=flat-square
[download-url]: https://npmjs.org/package/sofa-rpc-node

## 一、SOFARPC Node 简介

简单说它是 [SOFARPC](https://github.com/alipay/sofa-rpc) 的 Nodejs 版实现,但本质上它是一个通用的 Nodejs RPC 解决方案。Nodejs RPC 在阿里和蚂蚁内部已经发展了四五年时间,如今广泛应用于各类业务场景,并经历了多次双 11 大促的考验。功能方面从基本的服务发布、寻址、点对点远程调用能力;到各种路由、负载均衡策略;再到故障隔离、熔断等高级功能,已逐渐发展成一个高可扩展性、高性能、生产级的 RPC 框架。
简单说它是 [SOFARPC](https://github.com/sofastack/sofa-rpc) 的 Nodejs 版实现,但本质上它是一个通用的 Nodejs RPC 解决方案。Nodejs RPC 在阿里和蚂蚁内部已经发展了四五年时间,如今广泛应用于各类业务场景,并经历了多次双 11 大促的考验。功能方面从基本的服务发布、寻址、点对点远程调用能力;到各种路由、负载均衡策略;再到故障隔离、熔断等高级功能,已逐渐发展成一个高可扩展性、高性能、生产级的 RPC 框架。

## 二、模块划分

Expand All @@ -28,7 +27,7 @@ SOFARPC Node 主要包含了四个子模块,分别是:
- __registry:__ 服务注册中心抽象及实现(目前提供 zookeeper 实现)
- __test:__ RPC 测试工具类

```
```bash
.
└── lib
├── client
Expand All @@ -39,36 +38,37 @@ SOFARPC Node 主要包含了四个子模块,分别是:

## 三、快速上手

#### 安装
### 安装

```bash
$ npm install sofa-rpc-node --save
npm install sofa-rpc-node --save
```

#### 安装并启动 zookeeper
### 安装并启动 zookeeper

sofa-rpc-node 默认的注册中心实现基于 zookeeper,所以需要先启动一个 zookeeper 实例

从 Homebrew 安装(macOs)

```bash
$ brew install zookeeper
brew install zookeeper
```

启动 zk server(默认端口为 2181)

```bash
$ zkServer start
ZooKeeper JMX enabled by default
Using config: /usr/local/etc/zookeeper/zoo.cfg
Starting zookeeper ... STARTED
zkServer start

# ZooKeeper JMX enabled by default
# Using config: /usr/local/etc/zookeeper/zoo.cfg
# Starting zookeeper ... STARTED
```

#### 代码示例
### 代码示例

- 暴露一个 RPC 服务,并发布到注册中心
```js
'use strict';

```js
const { RpcServer } = require('sofa-rpc-node').server;
const { ZookeeperRegistry } = require('sofa-rpc-node').registry;
const logger = console;
Expand Down Expand Up @@ -103,9 +103,8 @@ server.start()
```

- 调用 RPC 服务(从注册中心获取服务列表)
```js
'use strict';

```js
const { RpcClient } = require('sofa-rpc-node').client;
const { ZookeeperRegistry } = require('sofa-rpc-node').registry;
const logger = console;
Expand Down Expand Up @@ -138,9 +137,8 @@ invoke().catch(console.error);
```

- 调用 RPC 服务(直连模式)
```js
'use strict';

```js
const { RpcClient } = require('sofa-rpc-node').client;
const logger = console;

Expand All @@ -163,9 +161,8 @@ invoke().catch(console.error);
```

- 测试 RPC Server 的方法(用于单元测试)
```js
'use strict';

```js
const request = require('sofa-rpc-node').test;
const { RpcServer } = require('sofa-rpc-node').server;
const logger = console;
Expand Down Expand Up @@ -203,6 +200,7 @@ describe('test/server.test.js', () => {
- 暴露和调用 protobuf 接口

通过 *.proto 来定义接口

```proto
syntax = "proto3";
Expand Down Expand Up @@ -232,9 +230,8 @@ enum Group {
```

服务端代码
```js
'use strict';

```js
const antpb = require('antpb');
const protocol = require('sofa-bolt-node');
const { RpcServer } = require('sofa-rpc-node').server;
Expand Down Expand Up @@ -277,9 +274,8 @@ server.start()
```

客户端代码
```js
'use strict';

```js
const antpb = require('antpb');
const protocol = require('sofa-bolt-node');
const { RpcClient } = require('sofa-rpc-node').client;
Expand Down Expand Up @@ -317,9 +313,9 @@ async function invoke() {
invoke().catch(console.error);
```

#### 最佳实践
### 最佳实践

虽然上面我们提供了示例代码,但是我们并不推荐您直接使用该模块,因为它的定位是 RPC 基础模块,只提供基本的 API,对于业务开发者可能并不是非常友好。我们的最佳实践是通过插件将 RPC 能力集成到 [eggjs](https://github.com/eggjs/egg) 框架里,提供更加直观友好的用户接口,让您就像使用本地方法一样使用 RPC。这块也会在近期开放,敬请期待!
虽然上面我们提供了示例代码,但是我们并不推荐您直接使用该模块,因为它的定位是 RPC 基础模块,只提供基本的 API,对于业务开发者可能并不是非常友好。我们的最佳实践是通过插件将 RPC 能力集成到 [Egg.js](https://github.com/eggjs/egg) 框架里,提供更加直观友好的用户接口,让您就像使用本地方法一样使用 RPC。这块也会在近期开放,敬请期待!


## 三、相关文档
Expand All @@ -329,10 +325,10 @@ invoke().catch(console.error);

## 四、如何贡献

请告知我们可以为你做些什么,不过在此之前,请检查一下是否有已经[存在的Bug或者意见](https://github.com/alipay/sofa-rpc-node/issues)
请告知我们可以为你做些什么,不过在此之前,请检查一下是否有已经[存在的Bug或者意见](https://github.com/sofastack/sofa-rpc-node/issues)

如果你是一个代码贡献者,请参考[代码贡献规范](https://github.com/eggjs/egg/blob/master/CONTRIBUTING.zh-CN.md)

## 五、开源协议

[MIT](https://github.com/alipay/sofa-rpc-node/blob/master/LICENSE)
[MIT](LICENSE)
25 changes: 10 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/alipay/sofa-rpc-node.git"
"url": "git+https://github.com/sofastack/sofa-rpc-node.git"
},
"keywords": [
"sofa",
"rpc"
"rpc",
"egg"
],
"author": "gxcsoccer <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/alipay/sofa-rpc-node/issues"
"url": "https://github.com/sofastack/sofa-rpc-node/issues"
},
"homepage": "https://github.com/alipay/sofa-rpc-node#readme",
"homepage": "https://github.com/sofastack/sofa-rpc-node#readme",
"dependencies": {
"address": "^1.1.2",
"await-event": "^2.1.0",
Expand All @@ -56,21 +57,15 @@
"contributors": "^0.5.1",
"detect-port": "^1.5.1",
"dubbo-remoting": "^2.1.4",
"egg-bin": "^4.14.1",
"eslint": "^7.3.1",
"eslint-config-egg": "^8.0.1",
"egg-bin": "^5.3.1",
"eslint": "^8.27.0",
"eslint-config-egg": "^12.1.0",
"mm": "^3.2.0",
"node-zookeeper-client": "^1.1.0",
"pedding": "^1.1.0"
"pedding": "^1.1.0",
"runscript": "^1.5.3"
},
"engines": {
"node": ">= 10.0.0"
},
"ci": {
"type": "github",
"version": "10, 12, 14",
"os": {
"github": "linux"
}
}
}
45 changes: 7 additions & 38 deletions test/scripts/zk.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,17 @@
'use strict';

const fs = require('fs');
const path = require('path');
const cp = require('child_process');
const runscript = require('runscript');

const cwd = path.join(__dirname, '../..');

async function detectZookeeper() {
return new Promise(resolve => {
const netstat = cp.spawn('netstat', [ '-an' ]);
const grep = cp.spawn('grep', [ '2181' ]);

netstat.stdout.on('data', data => {
grep.stdin.write(data);
});

netstat.stderr.on('data', data => {
console.error(`netstat stderr: ${data}`);
});

netstat.on('close', code => {
if (code !== 0) {
console.log(`netstat process exited with code ${code}`);
}
grep.stdin.end();
});

grep.stdout.on('data', data => {
console.log(data.toString());
});

grep.stderr.on('data', data => {
console.error(`grep stderr: ${data}`);
});

grep.on('close', code => {
if (code !== 0) {
console.log(`grep process exited with code ${code}`);
resolve(false);
} else {
resolve(true);
}
});
});
try {
await runscript('netstat -an | grep 2181');
return true;
} catch {
return false;
}
}

async function extract() {
Expand Down

0 comments on commit 590be81

Please sign in to comment.