oox 0.0.9 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +2 -2
- package/LICENSE +21 -21
- package/README.md +29 -29
- package/bin/argv.js +95 -95
- package/bin/cli.js +57 -57
- package/bin/configurer.js +77 -77
- package/bin/proxyer.js +94 -94
- package/bin/register.js +104 -104
- package/bin/starter.js +139 -139
- package/global.js +143 -13
- package/index.js +5 -8
- package/middleware.js +167 -0
- package/package.json +17 -17
- package/rpc/config.class.js +47 -47
- package/rpc/context.class.js +14 -14
- package/rpc/http.class.js +326 -326
- package/rpc/rpc.class.js +128 -130
- package/rpc/rpc.interface.class.js +119 -121
- package/rpc/socketio.class.js +230 -230
- package/service/service.class.js +81 -85
- package/service/socketio.class.js +144 -187
- package/setMap.class.js +67 -67
- package/socketio/client.class.js +189 -189
- package/socketio/server.class.js +221 -221
- package/socketio/socket.class.js +22 -22
- package/util.js +373 -352
- package/global.class.js +0 -124
package/global.class.js
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
const { getTraceIdByStack } = require ( './util' )
|
|
3
|
-
|
|
4
|
-
const Context = require ( './rpc/context.class' )
|
|
5
|
-
|
|
6
|
-
const RPC = require ( './rpc/rpc.interface.class' )
|
|
7
|
-
|
|
8
|
-
const Socket = require ( './socketio/socket.class' )
|
|
9
|
-
|
|
10
|
-
const SetMap = require ( './setMap.class' )
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
module.exports = class Global {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @type {[RPC]}
|
|
20
|
-
*/
|
|
21
|
-
instances = [ ]
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* all contexts map
|
|
27
|
-
* @type {Map<String,Context>}
|
|
28
|
-
*/
|
|
29
|
-
contexts = new Map ( )
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @type {Map<String,Socket>}
|
|
35
|
-
*/
|
|
36
|
-
sockets = new Map ( )
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* @type {SocketIOServer[]}
|
|
42
|
-
*/
|
|
43
|
-
socketIOServers = [ ]
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* @type {Map<String,Set<Socket>>}
|
|
49
|
-
*/
|
|
50
|
-
socketIORegistry = new SetMap
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* 生成随机不重复id
|
|
56
|
-
* @returns {String}
|
|
57
|
-
*/
|
|
58
|
-
genTraceId ( ) {
|
|
59
|
-
|
|
60
|
-
const uid = [
|
|
61
|
-
Math.floor ( Date.now ( ) / 1000 ).toString ( 16 ),
|
|
62
|
-
Math.floor ( Math.random ( ) * 0xffffffff ).toString ( 16 ).padStart ( 8, '0' )
|
|
63
|
-
]
|
|
64
|
-
|
|
65
|
-
return uid.join ( '' )
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* 获取链路跟踪上下文
|
|
72
|
-
* @param {Context} param0
|
|
73
|
-
*/
|
|
74
|
-
genContext ( { caller, callerId, traceId, ip, sourceIP } = { } ) {
|
|
75
|
-
|
|
76
|
-
const context = new Context ( )
|
|
77
|
-
|
|
78
|
-
if ( caller ) {
|
|
79
|
-
|
|
80
|
-
context.caller = caller
|
|
81
|
-
} else {
|
|
82
|
-
|
|
83
|
-
const primaryService = this.instances [ 0 ]
|
|
84
|
-
|
|
85
|
-
if ( primaryService ) context.caller = primaryService.name
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
context.traceId = traceId || this.genTraceId ( )
|
|
89
|
-
context.ip = ip
|
|
90
|
-
context.sourceIP = sourceIP || ip
|
|
91
|
-
context.callerId = callerId
|
|
92
|
-
|
|
93
|
-
return context
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
genContextByStack ( stack ) {
|
|
99
|
-
|
|
100
|
-
if ( !stack ) {
|
|
101
|
-
|
|
102
|
-
let trace = { }
|
|
103
|
-
|
|
104
|
-
Error.captureStackTrace ( trace )
|
|
105
|
-
|
|
106
|
-
stack = trace.stack
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const traceId = getTraceIdByStack ( stack )
|
|
110
|
-
|
|
111
|
-
if ( traceId ) {
|
|
112
|
-
|
|
113
|
-
const sourceContext = this.contexts.get ( traceId )
|
|
114
|
-
|
|
115
|
-
if ( sourceContext ) {
|
|
116
|
-
|
|
117
|
-
return this.genContext ( { traceId, sourceIP: sourceContext.sourceIP } )
|
|
118
|
-
} else {
|
|
119
|
-
|
|
120
|
-
return this.genContext ( { traceId } )
|
|
121
|
-
}
|
|
122
|
-
} else return this.genContext ( )
|
|
123
|
-
}
|
|
124
|
-
}
|