rocketmq-client-remoting-nodejs 0.0.0-stage → 0.0.1
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/README.en.md +428 -0
- package/README.md +424 -2
- package/dist/client/admin.d.ts +229 -0
- package/dist/client/admin.js +2462 -0
- package/dist/client/allocate.d.ts +48 -0
- package/dist/client/allocate.js +365 -0
- package/dist/client/backpressure.d.ts +23 -0
- package/dist/client/backpressure.js +95 -0
- package/dist/client/consumer.d.ts +294 -0
- package/dist/client/consumer.js +3095 -0
- package/dist/client/consumer_result.d.ts +129 -0
- package/dist/client/consumer_result.js +138 -0
- package/dist/client/consumer_stats.d.ts +69 -0
- package/dist/client/consumer_stats.js +258 -0
- package/dist/client/exception.d.ts +39 -0
- package/dist/client/exception.js +36 -0
- package/dist/client/hook.d.ts +145 -0
- package/dist/client/hook.js +171 -0
- package/dist/client/latency.d.ts +61 -0
- package/dist/client/latency.js +239 -0
- package/dist/client/lite_pull_consumer.d.ts +151 -0
- package/dist/client/lite_pull_consumer.js +1096 -0
- package/dist/client/mq_client.d.ts +188 -0
- package/dist/client/mq_client.js +1678 -0
- package/dist/client/mq_client_manager.d.ts +21 -0
- package/dist/client/mq_client_manager.js +129 -0
- package/dist/client/offset_store.d.ts +45 -0
- package/dist/client/offset_store.js +389 -0
- package/dist/client/open_tracing_hook.d.ts +52 -0
- package/dist/client/open_tracing_hook.js +241 -0
- package/dist/client/pop_api.d.ts +28 -0
- package/dist/client/pop_api.js +224 -0
- package/dist/client/pop_consumer.d.ts +23 -0
- package/dist/client/pop_consumer.js +719 -0
- package/dist/client/pop_process_queue.d.ts +15 -0
- package/dist/client/pop_process_queue.js +51 -0
- package/dist/client/process_queue.d.ts +49 -0
- package/dist/client/process_queue.js +261 -0
- package/dist/client/produce_accumulator.d.ts +75 -0
- package/dist/client/produce_accumulator.js +288 -0
- package/dist/client/producer.d.ts +231 -0
- package/dist/client/producer.js +1774 -0
- package/dist/client/pull_api.d.ts +26 -0
- package/dist/client/pull_api.js +264 -0
- package/dist/client/pull_consumer.d.ts +119 -0
- package/dist/client/pull_consumer.js +876 -0
- package/dist/client/pull_schedule_service.d.ts +71 -0
- package/dist/client/pull_schedule_service.js +424 -0
- package/dist/client/request_reply.d.ts +61 -0
- package/dist/client/request_reply.js +232 -0
- package/dist/client/retry_message.d.ts +2 -0
- package/dist/client/retry_message.js +27 -0
- package/dist/client/send_result.d.ts +57 -0
- package/dist/client/send_result.js +70 -0
- package/dist/client/top_addressing.d.ts +20 -0
- package/dist/client/top_addressing.js +75 -0
- package/dist/client/trace_context.d.ts +61 -0
- package/dist/client/trace_context.js +373 -0
- package/dist/client/trace_dispatcher.d.ts +31 -0
- package/dist/client/trace_dispatcher.js +236 -0
- package/dist/client/trace_hook.d.ts +23 -0
- package/dist/client/trace_hook.js +228 -0
- package/dist/client/traceparent.d.ts +9 -0
- package/dist/client/traceparent.js +86 -0
- package/dist/common/boundary_type.d.ts +7 -0
- package/dist/common/boundary_type.js +16 -0
- package/dist/common/compress.d.ts +28 -0
- package/dist/common/compress.js +512 -0
- package/dist/common/message.d.ts +129 -0
- package/dist/common/message.js +214 -0
- package/dist/common/messageClientIdSetter.d.ts +7 -0
- package/dist/common/messageClientIdSetter.js +48 -0
- package/dist/common/messageConst.d.ts +68 -0
- package/dist/common/messageConst.js +68 -0
- package/dist/common/messageDecoder.d.ts +40 -0
- package/dist/common/messageDecoder.js +504 -0
- package/dist/common/messageType.d.ts +11 -0
- package/dist/common/messageType.js +11 -0
- package/dist/common/message_accessor.d.ts +39 -0
- package/dist/common/message_accessor.js +135 -0
- package/dist/common/mixAll.d.ts +106 -0
- package/dist/common/mixAll.js +247 -0
- package/dist/common/recall_message_handle.d.ts +25 -0
- package/dist/common/recall_message_handle.js +98 -0
- package/dist/common/subscriptionData.d.ts +36 -0
- package/dist/common/subscriptionData.js +64 -0
- package/dist/common/sysflag.d.ts +129 -0
- package/dist/common/sysflag.js +96 -0
- package/dist/common/topic_config.d.ts +66 -0
- package/dist/common/topic_config.js +106 -0
- package/dist/common/topic_validator.d.ts +49 -0
- package/dist/common/topic_validator.js +115 -0
- package/dist/common/utilAll.d.ts +39 -0
- package/dist/common/utilAll.js +154 -0
- package/dist/common/validators.d.ts +25 -0
- package/dist/common/validators.js +80 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +36 -0
- package/dist/logging.d.ts +24 -0
- package/dist/logging.js +246 -0
- package/dist/remoting/acl.d.ts +16 -0
- package/dist/remoting/acl.js +39 -0
- package/dist/remoting/admin_body.d.ts +257 -0
- package/dist/remoting/admin_body.js +669 -0
- package/dist/remoting/bodies.d.ts +475 -0
- package/dist/remoting/bodies.js +1131 -0
- package/dist/remoting/client.d.ts +73 -0
- package/dist/remoting/client.js +591 -0
- package/dist/remoting/codes.d.ts +296 -0
- package/dist/remoting/codes.js +301 -0
- package/dist/remoting/exception.d.ts +45 -0
- package/dist/remoting/exception.js +58 -0
- package/dist/remoting/extra_info.d.ts +61 -0
- package/dist/remoting/extra_info.js +220 -0
- package/dist/remoting/headers.d.ts +758 -0
- package/dist/remoting/headers.js +1307 -0
- package/dist/remoting/heartbeat.d.ts +91 -0
- package/dist/remoting/heartbeat.js +227 -0
- package/dist/remoting/namespace.d.ts +14 -0
- package/dist/remoting/namespace.js +85 -0
- package/dist/remoting/pop_bodies.d.ts +58 -0
- package/dist/remoting/pop_bodies.js +214 -0
- package/dist/remoting/remotingCommand.d.ts +39 -0
- package/dist/remoting/remotingCommand.js +225 -0
- package/dist/remoting/route.d.ts +61 -0
- package/dist/remoting/route.js +288 -0
- package/dist/remoting/rpc_hooks.d.ts +31 -0
- package/dist/remoting/rpc_hooks.js +73 -0
- package/dist/remoting/serialize.d.ts +33 -0
- package/dist/remoting/serialize.js +372 -0
- package/dist/remoting/socks_proxy.d.ts +29 -0
- package/dist/remoting/socks_proxy.js +379 -0
- package/dist/remoting/static_topic.d.ts +49 -0
- package/dist/remoting/static_topic.js +244 -0
- package/dist/remoting/subscription.d.ts +65 -0
- package/dist/remoting/subscription.js +172 -0
- package/package.json +38 -4
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { Message } from '../common/message.js';
|
|
2
|
+
import { MessageQueue } from '../common/message.js';
|
|
3
|
+
import { SendResult } from './send_result.js';
|
|
4
|
+
export declare const CommunicationMode: {
|
|
5
|
+
SYNC: number;
|
|
6
|
+
ASYNC: number;
|
|
7
|
+
ONEWAY: number;
|
|
8
|
+
};
|
|
9
|
+
export declare class SendMessageContext {
|
|
10
|
+
producerGroup: string | null;
|
|
11
|
+
message: Message | null;
|
|
12
|
+
messageQueue: MessageQueue | null;
|
|
13
|
+
brokerAddr: string | null;
|
|
14
|
+
bornHost: string | null;
|
|
15
|
+
communicationMode: number;
|
|
16
|
+
sendResult: SendResult | null;
|
|
17
|
+
exception: Error | null;
|
|
18
|
+
msgId: string | null;
|
|
19
|
+
namespace: string | null;
|
|
20
|
+
msgType: string | null;
|
|
21
|
+
constructor(producerGroup?: string | null, message?: Message | null, messageQueue?: MessageQueue | null, communicationMode?: number, brokerAddr?: string | null);
|
|
22
|
+
}
|
|
23
|
+
export declare class ConsumeMessageContext {
|
|
24
|
+
consumerGroup: string | null;
|
|
25
|
+
msgList: any[] | null;
|
|
26
|
+
topic: string | null;
|
|
27
|
+
status: number | null;
|
|
28
|
+
mq: MessageQueue | null;
|
|
29
|
+
namespace: string | null;
|
|
30
|
+
props: Record<string, string> | null;
|
|
31
|
+
constructor(consumerGroup?: string | null, msgList?: any[] | null, topic?: string | null);
|
|
32
|
+
}
|
|
33
|
+
export declare class EndTransactionContext {
|
|
34
|
+
producerGroup: string | null;
|
|
35
|
+
message: Message | null;
|
|
36
|
+
msgId: string | null;
|
|
37
|
+
transactionId: string | null;
|
|
38
|
+
brokerAddr: string | null;
|
|
39
|
+
transactionState: number | null;
|
|
40
|
+
fromTransactionCheck: boolean;
|
|
41
|
+
constructor(producerGroup?: string | null, message?: Message | null, brokerAddr?: string | null);
|
|
42
|
+
}
|
|
43
|
+
export declare class CheckForbiddenContext {
|
|
44
|
+
namespace: string | null;
|
|
45
|
+
producerGroup: string | null;
|
|
46
|
+
topic: string | null;
|
|
47
|
+
message: Message | null;
|
|
48
|
+
brokerAddr: string | null;
|
|
49
|
+
forbid: boolean;
|
|
50
|
+
constructor(namespace?: string | null, producerGroup?: string | null, topic?: string | null, message?: Message | null);
|
|
51
|
+
}
|
|
52
|
+
export declare class FilterMessageContext {
|
|
53
|
+
namespace: string | null;
|
|
54
|
+
consumerGroup: string | null;
|
|
55
|
+
topic: string | null;
|
|
56
|
+
msgList: any[] | null;
|
|
57
|
+
mq: MessageQueue | null;
|
|
58
|
+
accessChannel: string | null;
|
|
59
|
+
unitMode: boolean;
|
|
60
|
+
propertyKeys: string[] | null;
|
|
61
|
+
constructor(consumerGroup?: string | null, topic?: string | null, msgList?: any[] | null);
|
|
62
|
+
}
|
|
63
|
+
export declare abstract class SendMessageHook {
|
|
64
|
+
getHookName(): string;
|
|
65
|
+
abstract sendMessageBefore(ctx: SendMessageContext): void;
|
|
66
|
+
abstract sendMessageAfter(ctx: SendMessageContext): void;
|
|
67
|
+
}
|
|
68
|
+
export declare abstract class ConsumeMessageHook {
|
|
69
|
+
getHookName(): string;
|
|
70
|
+
abstract consumeMessageBefore(ctx: ConsumeMessageContext): void;
|
|
71
|
+
abstract consumeMessageAfter(ctx: ConsumeMessageContext): void;
|
|
72
|
+
}
|
|
73
|
+
export declare abstract class EndTransactionHook {
|
|
74
|
+
getHookName(): string;
|
|
75
|
+
abstract endTransactionBefore(ctx: EndTransactionContext): void;
|
|
76
|
+
abstract endTransactionAfter(ctx: EndTransactionContext): void;
|
|
77
|
+
}
|
|
78
|
+
export declare abstract class CheckForbiddenHook {
|
|
79
|
+
getHookName(): string;
|
|
80
|
+
abstract checkForbidden(ctx: CheckForbiddenContext): void;
|
|
81
|
+
}
|
|
82
|
+
export declare abstract class FilterMessageHook {
|
|
83
|
+
getHookName(): string;
|
|
84
|
+
abstract filterMessage(ctx: FilterMessageContext): any[] | null;
|
|
85
|
+
}
|
|
86
|
+
export declare class DefaultSendMessageHook extends SendMessageHook {
|
|
87
|
+
getHookName(): string;
|
|
88
|
+
sendMessageBefore(_ctx: SendMessageContext): void;
|
|
89
|
+
sendMessageAfter(_ctx: SendMessageContext): void;
|
|
90
|
+
}
|
|
91
|
+
export declare class DefaultConsumeMessageHook extends ConsumeMessageHook {
|
|
92
|
+
getHookName(): string;
|
|
93
|
+
consumeMessageBefore(_ctx: ConsumeMessageContext): void;
|
|
94
|
+
consumeMessageAfter(_ctx: ConsumeMessageContext): void;
|
|
95
|
+
}
|
|
96
|
+
export declare class DefaultEndTransactionHook extends EndTransactionHook {
|
|
97
|
+
getHookName(): string;
|
|
98
|
+
endTransactionBefore(_ctx: EndTransactionContext): void;
|
|
99
|
+
endTransactionAfter(_ctx: EndTransactionContext): void;
|
|
100
|
+
}
|
|
101
|
+
export declare class DefaultCheckForbiddenHook extends CheckForbiddenHook {
|
|
102
|
+
getHookName(): string;
|
|
103
|
+
checkForbidden(_ctx: CheckForbiddenContext): void;
|
|
104
|
+
}
|
|
105
|
+
export declare class DefaultFilterMessageHook extends FilterMessageHook {
|
|
106
|
+
getHookName(): string;
|
|
107
|
+
filterMessage(ctx: FilterMessageContext): any[] | null;
|
|
108
|
+
}
|
|
109
|
+
declare class HookRegistry {
|
|
110
|
+
sendMessageHooks: SendMessageHook[];
|
|
111
|
+
consumeMessageHooks: ConsumeMessageHook[];
|
|
112
|
+
checkForbiddenHooks: CheckForbiddenHook[];
|
|
113
|
+
filterMessageHooks: FilterMessageHook[];
|
|
114
|
+
endTransactionHooks: EndTransactionHook[];
|
|
115
|
+
registerSendMessageHook(h: SendMessageHook): void;
|
|
116
|
+
registerConsumeMessageHook(h: ConsumeMessageHook): void;
|
|
117
|
+
registerCheckForbiddenHook(h: CheckForbiddenHook): void;
|
|
118
|
+
registerFilterMessageHook(h: FilterMessageHook): void;
|
|
119
|
+
registerEndTransactionHook(h: EndTransactionHook): void;
|
|
120
|
+
}
|
|
121
|
+
export declare const hookRegistry: HookRegistry;
|
|
122
|
+
declare const _default: {
|
|
123
|
+
CommunicationMode: {
|
|
124
|
+
SYNC: number;
|
|
125
|
+
ASYNC: number;
|
|
126
|
+
ONEWAY: number;
|
|
127
|
+
};
|
|
128
|
+
SendMessageContext: typeof SendMessageContext;
|
|
129
|
+
ConsumeMessageContext: typeof ConsumeMessageContext;
|
|
130
|
+
EndTransactionContext: typeof EndTransactionContext;
|
|
131
|
+
CheckForbiddenContext: typeof CheckForbiddenContext;
|
|
132
|
+
FilterMessageContext: typeof FilterMessageContext;
|
|
133
|
+
SendMessageHook: typeof SendMessageHook;
|
|
134
|
+
ConsumeMessageHook: typeof ConsumeMessageHook;
|
|
135
|
+
EndTransactionHook: typeof EndTransactionHook;
|
|
136
|
+
CheckForbiddenHook: typeof CheckForbiddenHook;
|
|
137
|
+
FilterMessageHook: typeof FilterMessageHook;
|
|
138
|
+
DefaultSendMessageHook: typeof DefaultSendMessageHook;
|
|
139
|
+
DefaultConsumeMessageHook: typeof DefaultConsumeMessageHook;
|
|
140
|
+
DefaultEndTransactionHook: typeof DefaultEndTransactionHook;
|
|
141
|
+
DefaultCheckForbiddenHook: typeof DefaultCheckForbiddenHook;
|
|
142
|
+
DefaultFilterMessageHook: typeof DefaultFilterMessageHook;
|
|
143
|
+
hookRegistry: HookRegistry;
|
|
144
|
+
};
|
|
145
|
+
export default _default;
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
export const CommunicationMode = {
|
|
2
|
+
SYNC: 0,
|
|
3
|
+
ASYNC: 1,
|
|
4
|
+
ONEWAY: 2,
|
|
5
|
+
};
|
|
6
|
+
export class SendMessageContext {
|
|
7
|
+
producerGroup;
|
|
8
|
+
message;
|
|
9
|
+
messageQueue;
|
|
10
|
+
brokerAddr;
|
|
11
|
+
bornHost;
|
|
12
|
+
communicationMode;
|
|
13
|
+
sendResult;
|
|
14
|
+
exception;
|
|
15
|
+
msgId;
|
|
16
|
+
namespace;
|
|
17
|
+
// Java-parity MessageType *name* on the context ('NORMAL_MSG' | 'TRANS_MSG_HALF'
|
|
18
|
+
// | 'TRANS_MSG_COMMIT' | 'DELAY_MSG' | 'ORDER_MSG'); hooks that report the
|
|
19
|
+
// message type (trace, OpenTracing) read this instead of re-classifying.
|
|
20
|
+
msgType;
|
|
21
|
+
constructor(producerGroup = null, message = null, messageQueue = null, communicationMode = CommunicationMode.SYNC, brokerAddr = null) {
|
|
22
|
+
this.producerGroup = producerGroup;
|
|
23
|
+
this.message = message;
|
|
24
|
+
this.messageQueue = messageQueue;
|
|
25
|
+
this.communicationMode = communicationMode;
|
|
26
|
+
this.brokerAddr = brokerAddr;
|
|
27
|
+
this.bornHost = null;
|
|
28
|
+
this.sendResult = null;
|
|
29
|
+
this.exception = null;
|
|
30
|
+
this.msgId = null;
|
|
31
|
+
this.namespace = null;
|
|
32
|
+
this.msgType = null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export class ConsumeMessageContext {
|
|
36
|
+
consumerGroup;
|
|
37
|
+
msgList;
|
|
38
|
+
topic;
|
|
39
|
+
status;
|
|
40
|
+
mq;
|
|
41
|
+
namespace;
|
|
42
|
+
props;
|
|
43
|
+
constructor(consumerGroup = null, msgList = null, topic = null) {
|
|
44
|
+
this.consumerGroup = consumerGroup;
|
|
45
|
+
this.msgList = msgList;
|
|
46
|
+
this.topic = topic;
|
|
47
|
+
this.status = null;
|
|
48
|
+
this.mq = null;
|
|
49
|
+
this.namespace = null;
|
|
50
|
+
this.props = null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export class EndTransactionContext {
|
|
54
|
+
producerGroup;
|
|
55
|
+
message;
|
|
56
|
+
msgId;
|
|
57
|
+
transactionId;
|
|
58
|
+
brokerAddr;
|
|
59
|
+
transactionState;
|
|
60
|
+
fromTransactionCheck;
|
|
61
|
+
constructor(producerGroup = null, message = null, brokerAddr = null) {
|
|
62
|
+
this.producerGroup = producerGroup;
|
|
63
|
+
this.message = message;
|
|
64
|
+
this.msgId = null;
|
|
65
|
+
this.transactionId = null;
|
|
66
|
+
this.brokerAddr = brokerAddr;
|
|
67
|
+
this.transactionState = null;
|
|
68
|
+
this.fromTransactionCheck = false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export class CheckForbiddenContext {
|
|
72
|
+
namespace;
|
|
73
|
+
producerGroup;
|
|
74
|
+
topic;
|
|
75
|
+
message;
|
|
76
|
+
brokerAddr;
|
|
77
|
+
forbid;
|
|
78
|
+
constructor(namespace = null, producerGroup = null, topic = null, message = null) {
|
|
79
|
+
this.namespace = namespace;
|
|
80
|
+
this.producerGroup = producerGroup;
|
|
81
|
+
this.topic = topic;
|
|
82
|
+
this.message = message;
|
|
83
|
+
this.brokerAddr = null;
|
|
84
|
+
this.forbid = false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
export class FilterMessageContext {
|
|
88
|
+
namespace;
|
|
89
|
+
consumerGroup;
|
|
90
|
+
topic;
|
|
91
|
+
msgList;
|
|
92
|
+
// The queue the rows came from and the channel they arrived on, filled by
|
|
93
|
+
// every delivery path before the hooks run.
|
|
94
|
+
mq;
|
|
95
|
+
accessChannel;
|
|
96
|
+
unitMode;
|
|
97
|
+
propertyKeys;
|
|
98
|
+
constructor(consumerGroup = null, topic = null, msgList = null) {
|
|
99
|
+
this.namespace = null;
|
|
100
|
+
this.consumerGroup = consumerGroup;
|
|
101
|
+
this.topic = topic;
|
|
102
|
+
this.msgList = msgList;
|
|
103
|
+
this.mq = null;
|
|
104
|
+
this.accessChannel = null;
|
|
105
|
+
this.unitMode = false;
|
|
106
|
+
this.propertyKeys = null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// ---- interfaces ----
|
|
110
|
+
export class SendMessageHook {
|
|
111
|
+
getHookName() { return 'SendMessageHook'; }
|
|
112
|
+
}
|
|
113
|
+
export class ConsumeMessageHook {
|
|
114
|
+
getHookName() { return 'ConsumeMessageHook'; }
|
|
115
|
+
}
|
|
116
|
+
export class EndTransactionHook {
|
|
117
|
+
getHookName() { return 'EndTransactionHook'; }
|
|
118
|
+
}
|
|
119
|
+
export class CheckForbiddenHook {
|
|
120
|
+
getHookName() { return 'CheckForbiddenHook'; }
|
|
121
|
+
}
|
|
122
|
+
export class FilterMessageHook {
|
|
123
|
+
getHookName() { return 'FilterMessageHook'; }
|
|
124
|
+
}
|
|
125
|
+
// ---- default no-op implementations ----
|
|
126
|
+
export class DefaultSendMessageHook extends SendMessageHook {
|
|
127
|
+
getHookName() { return 'DefaultSendMessageHook'; }
|
|
128
|
+
sendMessageBefore(_ctx) { }
|
|
129
|
+
sendMessageAfter(_ctx) { }
|
|
130
|
+
}
|
|
131
|
+
export class DefaultConsumeMessageHook extends ConsumeMessageHook {
|
|
132
|
+
getHookName() { return 'DefaultConsumeMessageHook'; }
|
|
133
|
+
consumeMessageBefore(_ctx) { }
|
|
134
|
+
consumeMessageAfter(_ctx) { }
|
|
135
|
+
}
|
|
136
|
+
export class DefaultEndTransactionHook extends EndTransactionHook {
|
|
137
|
+
getHookName() { return 'DefaultEndTransactionHook'; }
|
|
138
|
+
endTransactionBefore(_ctx) { }
|
|
139
|
+
endTransactionAfter(_ctx) { }
|
|
140
|
+
}
|
|
141
|
+
export class DefaultCheckForbiddenHook extends CheckForbiddenHook {
|
|
142
|
+
getHookName() { return 'DefaultCheckForbiddenHook'; }
|
|
143
|
+
checkForbidden(_ctx) { }
|
|
144
|
+
}
|
|
145
|
+
export class DefaultFilterMessageHook extends FilterMessageHook {
|
|
146
|
+
getHookName() { return 'DefaultFilterMessageHook'; }
|
|
147
|
+
filterMessage(ctx) {
|
|
148
|
+
return ctx.msgList;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
// ---- shared registry ----
|
|
152
|
+
class HookRegistry {
|
|
153
|
+
sendMessageHooks = [];
|
|
154
|
+
consumeMessageHooks = [];
|
|
155
|
+
checkForbiddenHooks = [];
|
|
156
|
+
filterMessageHooks = [];
|
|
157
|
+
endTransactionHooks = [];
|
|
158
|
+
registerSendMessageHook(h) { this.sendMessageHooks.push(h); }
|
|
159
|
+
registerConsumeMessageHook(h) { this.consumeMessageHooks.push(h); }
|
|
160
|
+
registerCheckForbiddenHook(h) { this.checkForbiddenHooks.push(h); }
|
|
161
|
+
registerFilterMessageHook(h) { this.filterMessageHooks.push(h); }
|
|
162
|
+
registerEndTransactionHook(h) { this.endTransactionHooks.push(h); }
|
|
163
|
+
}
|
|
164
|
+
export const hookRegistry = new HookRegistry();
|
|
165
|
+
export default {
|
|
166
|
+
CommunicationMode, SendMessageContext, ConsumeMessageContext, EndTransactionContext,
|
|
167
|
+
CheckForbiddenContext, FilterMessageContext, SendMessageHook, ConsumeMessageHook,
|
|
168
|
+
EndTransactionHook, CheckForbiddenHook, FilterMessageHook,
|
|
169
|
+
DefaultSendMessageHook, DefaultConsumeMessageHook, DefaultEndTransactionHook,
|
|
170
|
+
DefaultCheckForbiddenHook, DefaultFilterMessageHook, hookRegistry,
|
|
171
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { MessageQueue } from '../common/message.js';
|
|
2
|
+
export type ServiceDetector = (addr: string, timeoutMillis: number) => boolean | Promise<boolean>;
|
|
3
|
+
export type BrokerResolver = (brokerName: string) => string | null;
|
|
4
|
+
export declare function tcpDetect(addr: string, timeoutMillis: number): Promise<boolean>;
|
|
5
|
+
export declare class FaultItem {
|
|
6
|
+
name: string;
|
|
7
|
+
currentLatency: number;
|
|
8
|
+
startTimestamp: number;
|
|
9
|
+
reachableFlag: boolean;
|
|
10
|
+
checkStamp: number;
|
|
11
|
+
constructor(name: string);
|
|
12
|
+
updateNotAvailableDuration(duration: number): void;
|
|
13
|
+
isAvailable(): boolean;
|
|
14
|
+
isReachable(): boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare class LatencyFaultToleranceImpl {
|
|
17
|
+
faultItemTable: Record<string, FaultItem>;
|
|
18
|
+
detectTimeout: number;
|
|
19
|
+
detectInterval: number;
|
|
20
|
+
startDetectorEnable: boolean;
|
|
21
|
+
resolver: BrokerResolver | null;
|
|
22
|
+
serviceDetector: ServiceDetector | null;
|
|
23
|
+
private _detectorTimer;
|
|
24
|
+
updateFaultItem(name: string, currentLatency: number, notAvailableDuration: number, reachable: boolean): void;
|
|
25
|
+
isAvailable(name: string): boolean;
|
|
26
|
+
isReachable(name: string | null): boolean;
|
|
27
|
+
remove(name: string): void;
|
|
28
|
+
getFaultItem(name: string): FaultItem | null;
|
|
29
|
+
setDetectTimeout(timeout: number): void;
|
|
30
|
+
setDetectInterval(interval: number): void;
|
|
31
|
+
setStartDetectorEnable(enable: boolean): void;
|
|
32
|
+
setResolver(resolver: BrokerResolver | null): void;
|
|
33
|
+
setServiceDetector(detector: ServiceDetector | null): void;
|
|
34
|
+
detectByOneRound(): void;
|
|
35
|
+
startDetector(): void;
|
|
36
|
+
shutdown(): void;
|
|
37
|
+
}
|
|
38
|
+
export declare class MQFaultStrategy {
|
|
39
|
+
static LATENCY_MAX: number[];
|
|
40
|
+
static NOT_AVAILABLE_DURATION: number[];
|
|
41
|
+
latencyMax: number[];
|
|
42
|
+
notAvailableDuration: number[];
|
|
43
|
+
sendLatencyFaultEnable: boolean;
|
|
44
|
+
latencyFaultTolerance: LatencyFaultToleranceImpl;
|
|
45
|
+
constructor(sendLatencyFaultEnable?: boolean);
|
|
46
|
+
selectOneMessageQueue(tpInfo: any, lastBrokerName?: string | null, resetIndex?: boolean): MessageQueue | null;
|
|
47
|
+
updateFaultItem(brokerName: string, currentLatency: number, isolation: boolean, reachable?: boolean): void;
|
|
48
|
+
_computeNotAvailableDuration(currentLatency: number): number;
|
|
49
|
+
isStartDetectorEnable(): boolean;
|
|
50
|
+
setStartDetectorEnable(enable: boolean): void;
|
|
51
|
+
setResolver(resolver: BrokerResolver | null): void;
|
|
52
|
+
setServiceDetector(detector: ServiceDetector | null): void;
|
|
53
|
+
startDetector(): void;
|
|
54
|
+
shutdown(): void;
|
|
55
|
+
}
|
|
56
|
+
declare const _default: {
|
|
57
|
+
FaultItem: typeof FaultItem;
|
|
58
|
+
LatencyFaultToleranceImpl: typeof LatencyFaultToleranceImpl;
|
|
59
|
+
MQFaultStrategy: typeof MQFaultStrategy;
|
|
60
|
+
};
|
|
61
|
+
export default _default;
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
// -*- coding: utf-8 -*-
|
|
2
|
+
// Latency fault tolerance.
|
|
3
|
+
//
|
|
4
|
+
// MQFaultStrategy decides which broker queue to pick next, avoiding brokers
|
|
5
|
+
// that were isolated after recent high latency or send failures (provided
|
|
6
|
+
// sendLatencyFaultEnable is on).
|
|
7
|
+
import { connect as netConnect } from 'node:net';
|
|
8
|
+
import { getLogger } from "../logging.js";
|
|
9
|
+
const logger = getLogger('client.latency');
|
|
10
|
+
// node's default detector: a single pure TCP connect probe. It runs only on the detector timer and never on the data path.
|
|
11
|
+
export function tcpDetect(addr, timeoutMillis) {
|
|
12
|
+
return new Promise((resolve) => {
|
|
13
|
+
const sep = addr.lastIndexOf(':');
|
|
14
|
+
if (sep < 0) {
|
|
15
|
+
resolve(false);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const host = addr.substring(0, sep);
|
|
19
|
+
const port = parseInt(addr.substring(sep + 1), 10);
|
|
20
|
+
if (!Number.isFinite(port) || port <= 0) {
|
|
21
|
+
resolve(false);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
let settled = false;
|
|
25
|
+
const finish = (ok) => {
|
|
26
|
+
if (settled)
|
|
27
|
+
return;
|
|
28
|
+
settled = true;
|
|
29
|
+
try {
|
|
30
|
+
sock.destroy();
|
|
31
|
+
}
|
|
32
|
+
catch (e) { /* ignore */ }
|
|
33
|
+
resolve(ok);
|
|
34
|
+
};
|
|
35
|
+
const sock = netConnect(port, host);
|
|
36
|
+
sock.setTimeout(timeoutMillis);
|
|
37
|
+
sock.once('connect', () => finish(true));
|
|
38
|
+
sock.once('timeout', () => finish(false));
|
|
39
|
+
sock.once('error', () => finish(false));
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
export class FaultItem {
|
|
43
|
+
name;
|
|
44
|
+
currentLatency;
|
|
45
|
+
startTimestamp;
|
|
46
|
+
reachableFlag;
|
|
47
|
+
// The next moment the detector may re-probe this item.
|
|
48
|
+
checkStamp;
|
|
49
|
+
constructor(name) {
|
|
50
|
+
this.name = name;
|
|
51
|
+
this.currentLatency = 0;
|
|
52
|
+
this.startTimestamp = 0;
|
|
53
|
+
this.reachableFlag = true;
|
|
54
|
+
this.checkStamp = 0;
|
|
55
|
+
}
|
|
56
|
+
// Mark the broker unavailable until (now + duration). Only EXTENDS an
|
|
57
|
+
// existing isolation window, never shortens it (updates only when
|
|
58
|
+
// `duration > 0 && now + duration > start`).
|
|
59
|
+
updateNotAvailableDuration(duration) {
|
|
60
|
+
if (duration > 0 && Date.now() + duration > this.startTimestamp) {
|
|
61
|
+
this.startTimestamp = Date.now() + duration;
|
|
62
|
+
logger.info('%s will be isolated for %d ms.', this.name, duration);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
isAvailable() {
|
|
66
|
+
return Date.now() >= this.startTimestamp;
|
|
67
|
+
}
|
|
68
|
+
isReachable() {
|
|
69
|
+
return this.reachableFlag;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export class LatencyFaultToleranceImpl {
|
|
73
|
+
faultItemTable = {};
|
|
74
|
+
// Defaults: probe timeout 200ms, per-item probe interval 2s, detector switch off.
|
|
75
|
+
detectTimeout = 200;
|
|
76
|
+
detectInterval = 2000;
|
|
77
|
+
startDetectorEnable = false;
|
|
78
|
+
resolver = null;
|
|
79
|
+
serviceDetector = null;
|
|
80
|
+
_detectorTimer = null;
|
|
81
|
+
updateFaultItem(name, currentLatency, notAvailableDuration, reachable) {
|
|
82
|
+
let item = this.faultItemTable[name];
|
|
83
|
+
if (item == null) {
|
|
84
|
+
item = new FaultItem(name);
|
|
85
|
+
this.faultItemTable[name] = item;
|
|
86
|
+
}
|
|
87
|
+
item.currentLatency = currentLatency;
|
|
88
|
+
item.updateNotAvailableDuration(notAvailableDuration);
|
|
89
|
+
item.reachableFlag = reachable;
|
|
90
|
+
}
|
|
91
|
+
isAvailable(name) {
|
|
92
|
+
const item = this.faultItemTable[name];
|
|
93
|
+
if (item != null)
|
|
94
|
+
return item.isAvailable();
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
isReachable(name) {
|
|
98
|
+
if (name == null)
|
|
99
|
+
return false;
|
|
100
|
+
const item = this.faultItemTable[name];
|
|
101
|
+
if (item != null)
|
|
102
|
+
return item.isReachable();
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
remove(name) {
|
|
106
|
+
delete this.faultItemTable[name];
|
|
107
|
+
}
|
|
108
|
+
getFaultItem(name) {
|
|
109
|
+
return this.faultItemTable[name] != null ? this.faultItemTable[name] : null;
|
|
110
|
+
}
|
|
111
|
+
setDetectTimeout(timeout) { this.detectTimeout = timeout; }
|
|
112
|
+
setDetectInterval(interval) { this.detectInterval = interval; }
|
|
113
|
+
setStartDetectorEnable(enable) { this.startDetectorEnable = enable; }
|
|
114
|
+
setResolver(resolver) { this.resolver = resolver; }
|
|
115
|
+
setServiceDetector(detector) { this.serviceDetector = detector; }
|
|
116
|
+
// detectByOneRound: walk every item whose checkStamp is due, pushing the
|
|
117
|
+
// stamp forward FIRST before probing, so one slow probe cannot re-trigger on
|
|
118
|
+
// the same item. node's default detector is promise-based, so reachability
|
|
119
|
+
// flips land in the promise callback; a synchronous detector flips
|
|
120
|
+
// immediately.
|
|
121
|
+
detectByOneRound() {
|
|
122
|
+
for (const key of Object.keys(this.faultItemTable)) {
|
|
123
|
+
const brokerItem = this.faultItemTable[key];
|
|
124
|
+
if (brokerItem == null)
|
|
125
|
+
continue;
|
|
126
|
+
if (Date.now() - brokerItem.checkStamp >= 0) {
|
|
127
|
+
brokerItem.checkStamp = Date.now() + this.detectInterval;
|
|
128
|
+
const brokerAddr = this.resolver != null ? this.resolver(brokerItem.name) : null;
|
|
129
|
+
if (brokerAddr == null) {
|
|
130
|
+
delete this.faultItemTable[key];
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (this.serviceDetector == null)
|
|
134
|
+
continue;
|
|
135
|
+
const serviceOK = this.serviceDetector(brokerAddr, this.detectTimeout);
|
|
136
|
+
Promise.resolve(serviceOK).then((ok) => {
|
|
137
|
+
if (ok && !brokerItem.reachableFlag) {
|
|
138
|
+
logger.info('%s is reachable now, then it can be used.', brokerItem.name);
|
|
139
|
+
brokerItem.reachableFlag = true;
|
|
140
|
+
}
|
|
141
|
+
}).catch(() => { });
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// Start the detector: a fixed 3s first round and 3s period; each tick does work only when startDetectorEnable is true.
|
|
146
|
+
startDetector() {
|
|
147
|
+
if (this._detectorTimer != null)
|
|
148
|
+
return;
|
|
149
|
+
const tick = () => {
|
|
150
|
+
try {
|
|
151
|
+
if (this.startDetectorEnable)
|
|
152
|
+
this.detectByOneRound();
|
|
153
|
+
}
|
|
154
|
+
catch (e) {
|
|
155
|
+
logger.warning('unexpected exception raised while detecting service reachability: %s', e.message);
|
|
156
|
+
}
|
|
157
|
+
this._detectorTimer = setTimeout(tick, 3000);
|
|
158
|
+
if (typeof this._detectorTimer.unref === 'function')
|
|
159
|
+
this._detectorTimer.unref();
|
|
160
|
+
};
|
|
161
|
+
this._detectorTimer = setTimeout(tick, 3000);
|
|
162
|
+
if (typeof this._detectorTimer.unref === 'function')
|
|
163
|
+
this._detectorTimer.unref();
|
|
164
|
+
}
|
|
165
|
+
shutdown() {
|
|
166
|
+
if (this._detectorTimer != null) {
|
|
167
|
+
clearTimeout(this._detectorTimer);
|
|
168
|
+
this._detectorTimer = null;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
export class MQFaultStrategy {
|
|
173
|
+
static LATENCY_MAX = [50, 100, 550, 1800, 3000, 5000, 15000];
|
|
174
|
+
static NOT_AVAILABLE_DURATION = [0, 0, 2000, 5000, 6000, 10000, 30000];
|
|
175
|
+
latencyMax;
|
|
176
|
+
notAvailableDuration;
|
|
177
|
+
sendLatencyFaultEnable;
|
|
178
|
+
latencyFaultTolerance;
|
|
179
|
+
constructor(sendLatencyFaultEnable = false) {
|
|
180
|
+
this.latencyMax = MQFaultStrategy.LATENCY_MAX;
|
|
181
|
+
this.notAvailableDuration = MQFaultStrategy.NOT_AVAILABLE_DURATION;
|
|
182
|
+
this.sendLatencyFaultEnable = sendLatencyFaultEnable;
|
|
183
|
+
this.latencyFaultTolerance = new LatencyFaultToleranceImpl();
|
|
184
|
+
}
|
|
185
|
+
selectOneMessageQueue(tpInfo, lastBrokerName = null, resetIndex = false) {
|
|
186
|
+
if (!this.sendLatencyFaultEnable) {
|
|
187
|
+
return tpInfo.selectOneMessageQueue(lastBrokerName, resetIndex);
|
|
188
|
+
}
|
|
189
|
+
const mqs = tpInfo.msgQueueList || [];
|
|
190
|
+
for (let i = 0; i < mqs.length; i++) {
|
|
191
|
+
const mq = tpInfo.selectOneMessageQueue(lastBrokerName, resetIndex);
|
|
192
|
+
if (this.latencyFaultTolerance.isAvailable(mq.getBrokerName())) {
|
|
193
|
+
return mq;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (this.latencyFaultTolerance.isReachable(lastBrokerName)) {
|
|
197
|
+
return tpInfo.selectOneMessageQueue(lastBrokerName, resetIndex);
|
|
198
|
+
}
|
|
199
|
+
return tpInfo.selectOneMessageQueue(null, resetIndex);
|
|
200
|
+
}
|
|
201
|
+
// updateFaultItem: takes effect only when sendLatencyFaultEnable is on; the
|
|
202
|
+
// isolation duration comes from the latency table, and in the isolation
|
|
203
|
+
// state currentLatency is treated as a FIXED 10000ms (not the 30s lower
|
|
204
|
+
// bound): `computeNotAvailableDuration(isolation ? 10000 : currentLatency)`.
|
|
205
|
+
updateFaultItem(brokerName, currentLatency, isolation, reachable = true) {
|
|
206
|
+
if (!this.sendLatencyFaultEnable)
|
|
207
|
+
return;
|
|
208
|
+
const duration = this._computeNotAvailableDuration(isolation ? 10000 : currentLatency);
|
|
209
|
+
this.latencyFaultTolerance.updateFaultItem(brokerName, currentLatency, duration, reachable);
|
|
210
|
+
}
|
|
211
|
+
_computeNotAvailableDuration(currentLatency) {
|
|
212
|
+
for (let i = this.latencyMax.length - 1; i >= 0; i--) {
|
|
213
|
+
if (currentLatency >= this.latencyMax[i]) {
|
|
214
|
+
return this.notAvailableDuration[i];
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return 0;
|
|
218
|
+
}
|
|
219
|
+
// ---- startDetector-related switches and injection ----
|
|
220
|
+
isStartDetectorEnable() {
|
|
221
|
+
return this.latencyFaultTolerance.startDetectorEnable;
|
|
222
|
+
}
|
|
223
|
+
setStartDetectorEnable(enable) {
|
|
224
|
+
this.latencyFaultTolerance.setStartDetectorEnable(enable);
|
|
225
|
+
}
|
|
226
|
+
setResolver(resolver) {
|
|
227
|
+
this.latencyFaultTolerance.setResolver(resolver);
|
|
228
|
+
}
|
|
229
|
+
setServiceDetector(detector) {
|
|
230
|
+
this.latencyFaultTolerance.setServiceDetector(detector);
|
|
231
|
+
}
|
|
232
|
+
startDetector() {
|
|
233
|
+
this.latencyFaultTolerance.startDetector();
|
|
234
|
+
}
|
|
235
|
+
shutdown() {
|
|
236
|
+
this.latencyFaultTolerance.shutdown();
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
export default { FaultItem, LatencyFaultToleranceImpl, MQFaultStrategy };
|