Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
creasy2010 committed Jul 4, 2018
2 parents 367a885 + 78a2813 commit f91c77e
Show file tree
Hide file tree
Showing 24 changed files with 495 additions and 70 deletions.
197 changes: 181 additions & 16 deletions README.md
Expand Up @@ -12,7 +12,7 @@

## Features

1. Keep it Simple
1. Keep it Simple (build tools for humans).

2. Support zookeeper as register center

Expand All @@ -22,17 +22,17 @@

5. Support Directly Dubbo (const Dubbo = DirectlyDubbo({..}))

6. Middleware, Easy to extend.
6. Middleware the same as Koa middleware, Easy to extend.

7. Tracing
7. Tracing (runtime info, call stack)

8. Supported Dubbox

9. Typescript type definition

10. Convert java dubbo interface to typescript module

11. socket-worker auto retry
11. SocketWorker auto retry

## Getting Started

Expand Down Expand Up @@ -324,27 +324,192 @@ app.beforeStart(async () => {
});
```

## dubbo's subscriber
## How to trace dubbo2.js runtime system info?

```javascript
const dubbo = Dubbo.from(/*...*/);

//通过subscribe
dubbo.subcribe({
onReady: () => {
//dubbo was ready.
//TODO for example logger
},
onSysError: err => {
//dubbo occur error
//TODO dingTalkRobot.send('error')
},
onStatistics: stat => {
//get invoke time statistics info
//in order to know load whether balance
onTrace(msg: ITrace) {
//logger msg
},
});
```

You will get all runtim system info just like this.

```text
{ type: 'INFO', msg: 'dubbo:bootstrap version => 2.1.5' }
{ type: 'INFO', msg: 'connected to zkserver localhost:2181' }
{ type: 'INFO',
msg: 'ServerAgent create socket-pool: 172.19.6.203:20880' }
{ type: 'INFO',
msg: 'socket-pool: 172.19.6.203:20880 poolSize: 1' }
{ type: 'INFO',
msg: 'new SocketWorker#1 |> 172.19.6.203:20880' }
{ type: 'INFO',
msg: 'SocketWorker#1 =connecting=> 172.19.6.203:20880' }
{ type: 'INFO',
msg: 'SocketWorker#1 <=connected=> 172.19.6.203:20880' }
{ type: 'INFO', msg: 'scheduler is ready' }
{ type: 'INFO',
msg: 'trigger watch /dubbo/com.alibaba.dubbo.demo.DemoProvider/providers, type: NODE_CHILDREN_CHANGED' }
{ type: 'INFO',
msg: 'trigger watch /dubbo/com.alibaba.dubbo.demo.ErrorProvider/providers, type: NODE_CHILDREN_CHANGED' }
{ type: 'INFO',
msg: 'trigger watch /dubbo/com.alibaba.dubbo.demo.BasicTypeProvider/providers, type: NODE_CHILDREN_CHANGED' }
{ type: 'ERR',
msg: Error: Can not be found any agents
at Object.Scheduler._handleZkClientOnData [as onData] (/Users/hufeng/Github/dubbo2.js/packages/dubbo/es7/scheduler.js:68:29)
at EventEmitter.<anonymous> (/Users/hufeng/Github/dubbo2.js/packages/dubbo/es7/zookeeper.js:275:30)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:118:7) }
{ type: 'ERR',
msg: Error: SocketWorker#1 <=closed=> 172.19.6.203:20880 retry: 6
at SocketWorker._onClose (/Users/hufeng/Github/dubbo2.js/packages/dubbo/es7/socket-worker.js:78:29)
at Socket.emit (events.js:180:13)
at TCP._handle.close [as _onclose] (net.js:541:12) }
{ type: 'INFO',
msg: 'SocketWorker#1 =connecting=> 172.19.6.203:20880' }
{ type: 'ERR',
msg:
{ Error: connect ECONNREFUSED 172.19.6.203:20880
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1173:14)
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '172.19.6.203',
port: 20880 } }
{ type: 'ERR',
msg: Error: SocketWorker#1 <=closed=> 172.19.6.203:20880 retry: 5
at SocketWorker._onClose (/Users/hufeng/Github/dubbo2.js/packages/dubbo/es7/socket-worker.js:78:29)
at Socket.emit (events.js:180:13)
at TCP._handle.close [as _onclose] (net.js:541:12) }
{ type: 'INFO',
msg: 'trigger watch /dubbo/com.alibaba.dubbo.demo.DemoProvider/providers, type: NODE_CHILDREN_CHANGED' }
{ type: 'INFO',
msg: 'trigger watch /dubbo/com.alibaba.dubbo.demo.BasicTypeProvider/providers, type: NODE_CHILDREN_CHANGED' }
{ type: 'INFO',
msg: 'trigger watch /dubbo/com.alibaba.dubbo.demo.ErrorProvider/providers, type: NODE_CHILDREN_CHANGED' }
{ type: 'INFO',
msg: 'trigger watch /dubbo/com.alibaba.dubbo.demo.ErrorProvider/providers, type: NODE_CHILDREN_CHANGED' }
{ type: 'INFO',
msg: 'trigger watch /dubbo/com.alibaba.dubbo.demo.DemoProvider/providers, type: NODE_CHILDREN_CHANGED' }
{ type: 'INFO',
msg: 'trigger watch /dubbo/com.alibaba.dubbo.demo.BasicTypeProvider/providers, type: NODE_CHILDREN_CHANGED' }
{ type: 'ERR',
msg: Error: Can not be found any agents
at Object.Scheduler._handleZkClientOnData [as onData] (/Users/hufeng/Github/dubbo2.js/packages/dubbo/es7/scheduler.js:68:29)
at EventEmitter.<anonymous> (/Users/hufeng/Github/dubbo2.js/packages/dubbo/es7/zookeeper.js:275:30)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:118:7) }
{ type: 'INFO',
msg: 'SocketWorker#1 =connecting=> 172.19.6.203:20880' }
{ type: 'ERR',
msg:
{ Error: connect ECONNREFUSED 172.19.6.203:20880
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1173:14)
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '172.19.6.203',
port: 20880 } }
{ type: 'ERR',
msg: Error: SocketWorker#1 <=closed=> 172.19.6.203:20880 retry: 4
at SocketWorker._onClose (/Users/hufeng/Github/dubbo2.js/packages/dubbo/es7/socket-worker.js:78:29)
at Socket.emit (events.js:180:13)
at TCP._handle.close [as _onclose] (net.js:541:12) }
{ type: 'INFO',
msg: 'SocketWorker#1 =connecting=> 172.19.6.203:20880' }
{ type: 'ERR',
msg:
{ Error: connect ECONNREFUSED 172.19.6.203:20880
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1173:14)
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '172.19.6.203',
port: 20880 } }
{ type: 'ERR',
msg: Error: SocketWorker#1 <=closed=> 172.19.6.203:20880 retry: 3
at SocketWorker._onClose (/Users/hufeng/Github/dubbo2.js/packages/dubbo/es7/socket-worker.js:78:29)
at Socket.emit (events.js:180:13)
at TCP._handle.close [as _onclose] (net.js:541:12) }
{ type: 'INFO',
msg: 'SocketWorker#1 =connecting=> 172.19.6.203:20880' }
{ type: 'ERR',
msg:
{ Error: connect ECONNREFUSED 172.19.6.203:20880
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1173:14)
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '172.19.6.203',
port: 20880 } }
{ type: 'ERR',
msg: Error: SocketWorker#1 <=closed=> 172.19.6.203:20880 retry: 2
at SocketWorker._onClose (/Users/hufeng/Github/dubbo2.js/packages/dubbo/es7/socket-worker.js:78:29)
at Socket.emit (events.js:180:13)
at TCP._handle.close [as _onclose] (net.js:541:12) }
{ type: 'INFO',
msg: 'SocketWorker#1 =connecting=> 172.19.6.203:20880' }
{ type: 'ERR',
msg:
{ Error: connect ECONNREFUSED 172.19.6.203:20880
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1173:14)
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '172.19.6.203',
port: 20880 } }
{ type: 'ERR',
msg: Error: SocketWorker#1 <=closed=> 172.19.6.203:20880 retry: 1
at SocketWorker._onClose (/Users/hufeng/Github/dubbo2.js/packages/dubbo/es7/socket-worker.js:78:29)
at Socket.emit (events.js:180:13)
at TCP._handle.close [as _onclose] (net.js:541:12) }
{ type: 'INFO',
msg: 'SocketWorker#1 =connecting=> 172.19.6.203:20880' }
{ type: 'ERR',
msg:
{ Error: connect ECONNREFUSED 172.19.6.203:20880
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1173:14)
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '172.19.6.203',
port: 20880 } }
{ type: 'ERR',
msg: Error: SocketWorker#1 <=closed=> 172.19.6.203:20880 retry: 0
at SocketWorker._onClose (/Users/hufeng/Github/dubbo2.js/packages/dubbo/es7/socket-worker.js:78:29)
at Socket.emit (events.js:180:13)
at TCP._handle.close [as _onclose] (net.js:541:12) }
{ type: 'ERR',
msg: Error: 172.19.6.203:20880's pool socket-worker had all closed. delete 172.19.6.203:20880
at ServerAgent._clearClosedPool (/Users/hufeng/Github/dubbo2.js/packages/dubbo/es7/server-agent.js:66:33)
at Object.onClose (/Users/hufeng/Github/dubbo2.js/packages/dubbo/es7/server-agent.js:51:34)
at SocketWorker._onClose (/Users/hufeng/Github/dubbo2.js/packages/dubbo/es7/socket-worker.js:97:34)
at Socket.emit (events.js:180:13)
at TCP._handle.close [as _onclose] (net.js:541:12) }
{ type: 'INFO',
msg: 'trigger watch /dubbo/com.alibaba.dubbo.demo.DemoProvider/providers, type: NODE_CHILDREN_CHANGED' }
{ type: 'INFO',
msg: 'ServerAgent create socket-pool: 172.19.6.203:20880' }
{ type: 'INFO',
msg: 'socket-pool: 172.19.6.203:20880 poolSize: 1' }
{ type: 'INFO',
msg: 'new SocketWorker#2 |> 172.19.6.203:20880' }
{ type: 'INFO',
msg: 'SocketWorker#2 =connecting=> 172.19.6.203:20880' }
{ type: 'INFO',
msg: 'SocketWorker#2 <=connected=> 172.19.6.203:20880' }
{ type: 'INFO', msg: 'scheduler is ready' }
{ type: 'INFO',
msg: 'trigger watch /dubbo/com.alibaba.dubbo.demo.BasicTypeProvider/providers, type: NODE_CHILDREN_CHANGED' }
{ type: 'INFO',
msg: 'trigger watch /dubbo/com.alibaba.dubbo.demo.ErrorProvider/providers, type: NODE_CHILDREN_CHANGED' }
```

## middleware

通过对调用链路的抽象使用和 koa 相同的 middleware 机制,方便自定义拦截器,比如 logger,
Expand Down
2 changes: 1 addition & 1 deletion packages/dubbo/package.json
@@ -1,6 +1,6 @@
{
"name": "dubbo2.js",
"version": "2.1.5",
"version": "2.1.6",
"main": "./es7/index.js",
"types": "./es7/typings/index.d.ts",
"license": "Apache Licence 2.0",
Expand Down
1 change: 1 addition & 0 deletions packages/dubbo/src/__tests__/async-test.ts
Expand Up @@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

async function hello() {
return {err: null, res: 'hello'};
}
Expand Down
18 changes: 7 additions & 11 deletions packages/dubbo/src/__tests__/binary-test.ts
Expand Up @@ -14,27 +14,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {binaryNum, convertBinaryNum} from '../binary';
import {fromBytes4, fromBytes8, toBytes4, toBytes8} from '../byte';

describe('binary test suite', () => {
it('test binaryNum', () => {
expect(binaryNum(1025, 4)).toEqual(new Buffer([0x00, 0x00, 0x04, 0x01]));
expect(binaryNum(201212, 4)).toEqual(new Buffer([0x00, 0x03, 0x11, 0xfc]));
expect(toBytes4(1025)).toEqual(new Buffer([0x00, 0x00, 0x04, 0x01]));
expect(toBytes4(201212)).toEqual(new Buffer([0x00, 0x03, 0x11, 0xfc]));
});

it('test convert number', () => {
expect(convertBinaryNum(new Buffer([0x00, 0x00, 0x04, 0x01]), 4)).toEqual(
1025,
);
expect(convertBinaryNum(new Buffer([0x00, 0x03, 0x11, 0xfc]), 4)).toEqual(
201212,
);
expect(fromBytes4(new Buffer([0x00, 0x00, 0x04, 0x01]))).toEqual(1025);
expect(fromBytes4(new Buffer([0x00, 0x03, 0x11, 0xfc]))).toEqual(201212);
});

it('test binary uuid', () => {
const seed = 13234234234234234234;
const buffer = binaryNum(seed, 8);
const num = convertBinaryNum(buffer, 8);
const buffer = toBytes8(seed);
const num = fromBytes8(buffer);
expect(seed).toEqual(num);
});
});
2 changes: 1 addition & 1 deletion packages/dubbo/src/__tests__/context-test.ts
Expand Up @@ -14,8 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import Context from '../context';
import java from 'js-to-java';
import Context from '../context';

describe('context test suite', () => {
it('test default Value', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/dubbo/src/__tests__/decode-buffer-test.ts
Expand Up @@ -15,8 +15,8 @@
* limitations under the License.
*/
import {Buffer} from 'buffer';
import DecodeBuffer from '../decode-buffer';
import {decode} from '../decode';
import DecodeBuffer from '../decode-buffer';

it('test receive right data', () => {
const buffer = Buffer.from([
Expand Down
2 changes: 1 addition & 1 deletion packages/dubbo/src/__tests__/directly-dubbo-test.ts
Expand Up @@ -14,9 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {DirectlyDubbo, java} from 'dubbo2.js';
import {
DemoProvider,
DemoProviderWrapper,
IDemoProvider,
} from './providers/com/alibaba/dubbo/demo/DemoProvider';
Expand Down
16 changes: 9 additions & 7 deletions packages/dubbo/src/__tests__/dubbo-hessian-parameter-test.ts
Expand Up @@ -14,14 +14,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {Dubbo, java} from 'dubbo2.js';

import {Dubbo} from 'dubbo2.js';
import {DemoProvider} from './providers/com/alibaba/dubbo/demo/DemoProvider';

const dubbo = new Dubbo({
const service = {
DemoProvider,
};

const dubbo = new Dubbo<typeof service>({
application: {name: '@qianmi/node-dubbo'},
register: 'localhost:2181',
dubboVersion: '2.0.0',
interfaces: ['com.alibaba.dubbo.demo.DemoProvider'],
service,
});

//use middleware
Expand All @@ -38,12 +42,10 @@ dubbo.use(async function test(ctx, next) {
);
});

const demoService = DemoProvider(dubbo);

describe('dubbo hessian parameter check test suite', () => {
it('test sayHello', async () => {
//@ts-ignore
const {res, err} = await demoService.sayHello('node');
const {res, err} = await dubbo.service.DemoProvider.sayHello('node');
expect(res).toEqual(null);
expect(err != null).toEqual(true);
expect(err.message).toMatch(/not all arguments are valid hessian type/);
Expand Down

0 comments on commit f91c77e

Please sign in to comment.