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,91 @@
|
|
|
1
|
+
import { SubscriptionData } from '../common/subscriptionData.js';
|
|
2
|
+
export declare const ConsumeType: {
|
|
3
|
+
CONSUME_ACTIVELY: string;
|
|
4
|
+
CONSUME_PASSIVELY: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const MessageModel: {
|
|
7
|
+
CLUSTERING: string;
|
|
8
|
+
BROADCASTING: string;
|
|
9
|
+
};
|
|
10
|
+
export declare const ConsumeFromWhere: {
|
|
11
|
+
CONSUME_FROM_LAST_OFFSET: string;
|
|
12
|
+
CONSUME_FROM_FIRST_OFFSET: string;
|
|
13
|
+
CONSUME_FROM_TIMESTAMP: string;
|
|
14
|
+
CONSUME_FROM_LAST_OFFSET_AND_FROM_MIN_WHEN_BOOT_FIRST: string;
|
|
15
|
+
CONSUME_FROM_MIN_OFFSET: string;
|
|
16
|
+
CONSUME_FROM_MAX_OFFSET: string;
|
|
17
|
+
};
|
|
18
|
+
export declare class ProducerData {
|
|
19
|
+
groupName: string;
|
|
20
|
+
enable: boolean;
|
|
21
|
+
constructor(groupName?: string);
|
|
22
|
+
toDict(): Record<string, any>;
|
|
23
|
+
static fromDict(d: Record<string, any>): ProducerData;
|
|
24
|
+
}
|
|
25
|
+
export declare class ConsumerData {
|
|
26
|
+
groupName: string;
|
|
27
|
+
consumeType: string;
|
|
28
|
+
messageModel: string;
|
|
29
|
+
consumeFromWhere: string;
|
|
30
|
+
subscriptionDataSet: SubscriptionData[];
|
|
31
|
+
unitMode: boolean;
|
|
32
|
+
constructor(groupName?: string, consumeType?: string, messageModel?: string, consumeFromWhere?: string);
|
|
33
|
+
toDict(): Record<string, any>;
|
|
34
|
+
static fromDict(d: Record<string, any>): ConsumerData;
|
|
35
|
+
}
|
|
36
|
+
export declare class HeartbeatData {
|
|
37
|
+
clientID: string;
|
|
38
|
+
producerDataSet: ProducerData[];
|
|
39
|
+
consumerDataSet: ConsumerData[];
|
|
40
|
+
withoutSub: boolean;
|
|
41
|
+
heartbeatFingerprint: number;
|
|
42
|
+
constructor(clientID?: string);
|
|
43
|
+
toDict(): Record<string, any>;
|
|
44
|
+
static fromDict(d: Record<string, any>): HeartbeatData;
|
|
45
|
+
encode(): Buffer;
|
|
46
|
+
static decode(data: Buffer): HeartbeatData;
|
|
47
|
+
cloneWithoutSubscriptions(): HeartbeatData;
|
|
48
|
+
computeHeartbeatFingerprint(): number;
|
|
49
|
+
}
|
|
50
|
+
export declare function heartbeatDataEncode(hd: HeartbeatData): Buffer;
|
|
51
|
+
export declare function heartbeatDataDecode(bs: Buffer): HeartbeatData;
|
|
52
|
+
export declare const heartbeatExtIsSupportV2 = "IS_SUPPORT_HEART_BEAT_V2";
|
|
53
|
+
export declare const heartbeatExtIsSubChange = "IS_SUB_CHANGE";
|
|
54
|
+
export interface HeartbeatV2Flags {
|
|
55
|
+
version: number;
|
|
56
|
+
supportV2: boolean;
|
|
57
|
+
subChange: boolean;
|
|
58
|
+
}
|
|
59
|
+
export declare function decodeHeartbeatV2Flags(response: {
|
|
60
|
+
version?: number;
|
|
61
|
+
extFields?: Record<string, string> | null;
|
|
62
|
+
} | null): HeartbeatV2Flags;
|
|
63
|
+
export declare function javaStringHash(text: string): number;
|
|
64
|
+
declare const _default: {
|
|
65
|
+
HeartbeatData: typeof HeartbeatData;
|
|
66
|
+
ConsumerData: typeof ConsumerData;
|
|
67
|
+
ProducerData: typeof ProducerData;
|
|
68
|
+
heartbeatDataEncode: typeof heartbeatDataEncode;
|
|
69
|
+
heartbeatDataDecode: typeof heartbeatDataDecode;
|
|
70
|
+
ConsumeType: {
|
|
71
|
+
CONSUME_ACTIVELY: string;
|
|
72
|
+
CONSUME_PASSIVELY: string;
|
|
73
|
+
};
|
|
74
|
+
MessageModel: {
|
|
75
|
+
CLUSTERING: string;
|
|
76
|
+
BROADCASTING: string;
|
|
77
|
+
};
|
|
78
|
+
ConsumeFromWhere: {
|
|
79
|
+
CONSUME_FROM_LAST_OFFSET: string;
|
|
80
|
+
CONSUME_FROM_FIRST_OFFSET: string;
|
|
81
|
+
CONSUME_FROM_TIMESTAMP: string;
|
|
82
|
+
CONSUME_FROM_LAST_OFFSET_AND_FROM_MIN_WHEN_BOOT_FIRST: string;
|
|
83
|
+
CONSUME_FROM_MIN_OFFSET: string;
|
|
84
|
+
CONSUME_FROM_MAX_OFFSET: string;
|
|
85
|
+
};
|
|
86
|
+
heartbeatExtIsSupportV2: string;
|
|
87
|
+
heartbeatExtIsSubChange: string;
|
|
88
|
+
decodeHeartbeatV2Flags: typeof decodeHeartbeatV2Flags;
|
|
89
|
+
javaStringHash: typeof javaStringHash;
|
|
90
|
+
};
|
|
91
|
+
export default _default;
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
// NOTE: the heartbeat SubscriptionData uses the SAME fields as
|
|
2
|
+
// common/subscriptionData.ts (topic, subString, tagsSet, codeSet, subVersion,
|
|
3
|
+
// expressionType, classFilterMode) and the same JSON keys, so we reuse it here.
|
|
4
|
+
// The heartbeat ConsumerData deliberately does NOT include consumeTimestamp /
|
|
5
|
+
// maxReconsumeTimes (those were 4.x-only); only 5.x fields are emitted.
|
|
6
|
+
import { SubscriptionData } from "../common/subscriptionData.js";
|
|
7
|
+
import { RemotingSerializable } from "./serialize.js";
|
|
8
|
+
export const ConsumeType = {
|
|
9
|
+
CONSUME_ACTIVELY: 'CONSUME_ACTIVELY',
|
|
10
|
+
CONSUME_PASSIVELY: 'CONSUME_PASSIVELY',
|
|
11
|
+
};
|
|
12
|
+
export const MessageModel = {
|
|
13
|
+
CLUSTERING: 'CLUSTERING',
|
|
14
|
+
BROADCASTING: 'BROADCASTING',
|
|
15
|
+
};
|
|
16
|
+
export const ConsumeFromWhere = {
|
|
17
|
+
CONSUME_FROM_LAST_OFFSET: 'CONSUME_FROM_LAST_OFFSET',
|
|
18
|
+
CONSUME_FROM_FIRST_OFFSET: 'CONSUME_FROM_FIRST_OFFSET',
|
|
19
|
+
CONSUME_FROM_TIMESTAMP: 'CONSUME_FROM_TIMESTAMP',
|
|
20
|
+
// Java parity: these three share the CONSUME_FROM_LAST_OFFSET branch in
|
|
21
|
+
// RebalancePushImpl#computePullFromWhereWithException (lines 171-173).
|
|
22
|
+
CONSUME_FROM_LAST_OFFSET_AND_FROM_MIN_WHEN_BOOT_FIRST: 'CONSUME_FROM_LAST_OFFSET_AND_FROM_MIN_WHEN_BOOT_FIRST',
|
|
23
|
+
CONSUME_FROM_MIN_OFFSET: 'CONSUME_FROM_MIN_OFFSET',
|
|
24
|
+
CONSUME_FROM_MAX_OFFSET: 'CONSUME_FROM_MAX_OFFSET',
|
|
25
|
+
};
|
|
26
|
+
export class ProducerData {
|
|
27
|
+
groupName;
|
|
28
|
+
enable;
|
|
29
|
+
constructor(groupName = '') {
|
|
30
|
+
this.groupName = groupName;
|
|
31
|
+
this.enable = true;
|
|
32
|
+
}
|
|
33
|
+
toDict() {
|
|
34
|
+
return { groupName: this.groupName, enable: this.enable };
|
|
35
|
+
}
|
|
36
|
+
static fromDict(d) {
|
|
37
|
+
const p = new ProducerData(d['groupName'] != null ? d['groupName'] : '');
|
|
38
|
+
if (d['enable'] === false)
|
|
39
|
+
p.enable = false;
|
|
40
|
+
return p;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export class ConsumerData {
|
|
44
|
+
groupName;
|
|
45
|
+
consumeType;
|
|
46
|
+
messageModel;
|
|
47
|
+
consumeFromWhere;
|
|
48
|
+
subscriptionDataSet;
|
|
49
|
+
unitMode;
|
|
50
|
+
constructor(groupName = '', consumeType = ConsumeType.CONSUME_PASSIVELY, messageModel = MessageModel.CLUSTERING, consumeFromWhere = ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET) {
|
|
51
|
+
this.groupName = groupName;
|
|
52
|
+
this.consumeType = consumeType;
|
|
53
|
+
this.messageModel = messageModel;
|
|
54
|
+
this.consumeFromWhere = consumeFromWhere;
|
|
55
|
+
this.subscriptionDataSet = [];
|
|
56
|
+
this.unitMode = false;
|
|
57
|
+
}
|
|
58
|
+
toDict() {
|
|
59
|
+
return {
|
|
60
|
+
groupName: this.groupName,
|
|
61
|
+
consumeType: this.consumeType,
|
|
62
|
+
messageModel: this.messageModel,
|
|
63
|
+
consumeFromWhere: this.consumeFromWhere,
|
|
64
|
+
subscriptionDataSet: this.subscriptionDataSet.map((s) => s.toDict()),
|
|
65
|
+
unitMode: this.unitMode,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
static fromDict(d) {
|
|
69
|
+
const cd = new ConsumerData(d['groupName'] != null ? d['groupName'] : '', d['consumeType'] != null ? d['consumeType'] : ConsumeType.CONSUME_PASSIVELY, d['messageModel'] != null ? d['messageModel'] : MessageModel.CLUSTERING, d['consumeFromWhere'] != null ? d['consumeFromWhere'] : ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET);
|
|
70
|
+
cd.unitMode = d['unitMode'] === true;
|
|
71
|
+
const set = d['subscriptionDataSet'] || [];
|
|
72
|
+
for (const sd of set) {
|
|
73
|
+
const sub = new SubscriptionData(sd['topic'], sd['subString']);
|
|
74
|
+
sub.subVersion = parseInt(sd['subVersion'] != null ? sd['subVersion'] : 0, 10);
|
|
75
|
+
sub.expressionType = sd['expressionType'] != null ? sd['expressionType'] : 'TAG';
|
|
76
|
+
sub.classFilterMode = sd['classFilterMode'] === true;
|
|
77
|
+
sub.tagsSet = new Set((sd['tagsSet'] || []).slice());
|
|
78
|
+
sub.codeSet = new Set((sd['codeSet'] || []).map((v) => parseInt(v, 10)));
|
|
79
|
+
cd.subscriptionDataSet.push(sub);
|
|
80
|
+
}
|
|
81
|
+
return cd;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export class HeartbeatData {
|
|
85
|
+
clientID;
|
|
86
|
+
producerDataSet;
|
|
87
|
+
consumerDataSet;
|
|
88
|
+
withoutSub;
|
|
89
|
+
// Heartbeat V2 pair: `heartbeatFingerprint` identifies this client's
|
|
90
|
+
// subscription snapshot and `withoutSub` asks the broker to skip the
|
|
91
|
+
// (unchanged) subscription registration. Both stay at their zero value on a
|
|
92
|
+
// V1 beat, which is what makes a V1 body indistinguishable from before.
|
|
93
|
+
heartbeatFingerprint;
|
|
94
|
+
constructor(clientID = '') {
|
|
95
|
+
this.clientID = clientID;
|
|
96
|
+
this.producerDataSet = [];
|
|
97
|
+
this.consumerDataSet = [];
|
|
98
|
+
this.withoutSub = false;
|
|
99
|
+
this.heartbeatFingerprint = 0;
|
|
100
|
+
}
|
|
101
|
+
toDict() {
|
|
102
|
+
return {
|
|
103
|
+
clientID: this.clientID,
|
|
104
|
+
producerDataSet: this.producerDataSet.map((p) => p.toDict()),
|
|
105
|
+
consumerDataSet: this.consumerDataSet.map((c) => c.toDict()),
|
|
106
|
+
heartbeatFingerprint: this.heartbeatFingerprint,
|
|
107
|
+
withoutSub: this.withoutSub,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
static fromDict(d) {
|
|
111
|
+
const hb = new HeartbeatData(d['clientID'] != null ? d['clientID'] : '');
|
|
112
|
+
for (const p of d['producerDataSet'] || [])
|
|
113
|
+
hb.producerDataSet.push(ProducerData.fromDict(p));
|
|
114
|
+
for (const c of d['consumerDataSet'] || [])
|
|
115
|
+
hb.consumerDataSet.push(ConsumerData.fromDict(c));
|
|
116
|
+
hb.withoutSub = d['withoutSub'] === true;
|
|
117
|
+
hb.heartbeatFingerprint = parseInt(d['heartbeatFingerprint'] != null ? d['heartbeatFingerprint'] : 0, 10) || 0;
|
|
118
|
+
return hb;
|
|
119
|
+
}
|
|
120
|
+
encode() {
|
|
121
|
+
return RemotingSerializable.encode(this.toDict());
|
|
122
|
+
}
|
|
123
|
+
static decode(data) {
|
|
124
|
+
return HeartbeatData.fromDict(RemotingSerializable.decode(data));
|
|
125
|
+
}
|
|
126
|
+
// The same body with every subscription set emptied and withoutSub flagged, so a
|
|
127
|
+
// V2 broker can skip subscription registration it already has. Nothing shared
|
|
128
|
+
// with the receiver is mutated: the ConsumerData entries are fresh values.
|
|
129
|
+
cloneWithoutSubscriptions() {
|
|
130
|
+
const out = new HeartbeatData(this.clientID);
|
|
131
|
+
out.heartbeatFingerprint = this.heartbeatFingerprint;
|
|
132
|
+
out.withoutSub = true;
|
|
133
|
+
for (const c of this.consumerDataSet) {
|
|
134
|
+
const cd = new ConsumerData(c.groupName, c.consumeType, c.messageModel, c.consumeFromWhere);
|
|
135
|
+
cd.unitMode = c.unitMode;
|
|
136
|
+
cd.subscriptionDataSet = [];
|
|
137
|
+
out.consumerDataSet.push(cd);
|
|
138
|
+
}
|
|
139
|
+
for (const p of this.producerDataSet) {
|
|
140
|
+
const pd = new ProducerData(p.groupName);
|
|
141
|
+
pd.enable = p.enable;
|
|
142
|
+
out.producerDataSet.push(pd);
|
|
143
|
+
}
|
|
144
|
+
return out;
|
|
145
|
+
}
|
|
146
|
+
// Fingerprint of this body's subscription snapshot: a hash of a NORMALISED
|
|
147
|
+
// rendering, with the fields that change per beat or per client stripped out
|
|
148
|
+
// (every subscription's subVersion, clientID, withoutSub, heartbeatFingerprint)
|
|
149
|
+
// and every set put in a defined order.
|
|
150
|
+
//
|
|
151
|
+
// Ordering matters more here than it does in a single-threaded reference
|
|
152
|
+
// implementation: registration order is not stable across beats in this
|
|
153
|
+
// runtime, so a rendering that kept it would report a subscription change on
|
|
154
|
+
// every heartbeat and the broker-side skip would never trigger.
|
|
155
|
+
//
|
|
156
|
+
// The number only has to be stable for THIS client while its subscriptions do
|
|
157
|
+
// not change and different as soon as they do — a broker compares one client's
|
|
158
|
+
// beats to each other, never across languages.
|
|
159
|
+
computeHeartbeatFingerprint() {
|
|
160
|
+
// Code-unit comparison, not localeCompare: a locale-sensitive collation would
|
|
161
|
+
// make the same subscriptions hash differently on two machines.
|
|
162
|
+
const byCodeUnit = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
|
163
|
+
const consumers = this.consumerDataSet
|
|
164
|
+
.map((c) => {
|
|
165
|
+
const d = c.toDict();
|
|
166
|
+
// SubscriptionData.toDict already emits tagsSet/codeSet in a defined
|
|
167
|
+
// order; only subVersion has to be normalised out — it is stamped with
|
|
168
|
+
// the registration time, so it changes on every beat.
|
|
169
|
+
d['subscriptionDataSet'] = (d['subscriptionDataSet'] || [])
|
|
170
|
+
.map((s) => { s['subVersion'] = 0; return s; })
|
|
171
|
+
.sort((a, b) => byCodeUnit(String(a['topic']), String(b['topic'])));
|
|
172
|
+
return d;
|
|
173
|
+
})
|
|
174
|
+
.sort((a, b) => byCodeUnit(String(a['groupName']), String(b['groupName'])));
|
|
175
|
+
const producers = this.producerDataSet
|
|
176
|
+
.map((p) => p.toDict())
|
|
177
|
+
.sort((a, b) => byCodeUnit(String(a['groupName']), String(b['groupName'])));
|
|
178
|
+
return javaStringHash(JSON.stringify({
|
|
179
|
+
clientID: '',
|
|
180
|
+
producerDataSet: producers,
|
|
181
|
+
consumerDataSet: consumers,
|
|
182
|
+
heartbeatFingerprint: 0,
|
|
183
|
+
withoutSub: false,
|
|
184
|
+
}));
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
export function heartbeatDataEncode(hd) {
|
|
188
|
+
return RemotingSerializable.encode(hd.toDict());
|
|
189
|
+
}
|
|
190
|
+
export function heartbeatDataDecode(bs) {
|
|
191
|
+
return HeartbeatData.fromDict(RemotingSerializable.decode(bs));
|
|
192
|
+
}
|
|
193
|
+
// ---------------- heartbeat V2 ----------------
|
|
194
|
+
// Ext-field names a V2-capable broker sets on the HEART_BEAT(34) response. Both
|
|
195
|
+
// travel as `true` / `false` TEXT, so a reader that defaults to false is the
|
|
196
|
+
// correct answer for a broker that never heard of V2.
|
|
197
|
+
export const heartbeatExtIsSupportV2 = 'IS_SUPPORT_HEART_BEAT_V2';
|
|
198
|
+
export const heartbeatExtIsSubChange = 'IS_SUB_CHANGE';
|
|
199
|
+
// Read the two V2 flags + the broker version off a heartbeat response. Missing
|
|
200
|
+
// ext fields (every pre-V2 broker, every stub) mean "not V2-capable", which keeps
|
|
201
|
+
// the client sending subscription-carrying bodies. Typed structurally so this
|
|
202
|
+
// module stays free of a remotingCommand import.
|
|
203
|
+
export function decodeHeartbeatV2Flags(response) {
|
|
204
|
+
const out = { version: response != null ? response.version : 0, supportV2: false, subChange: false };
|
|
205
|
+
if (response == null)
|
|
206
|
+
return out;
|
|
207
|
+
const ext = response.extFields || {};
|
|
208
|
+
const read = (key) => String(ext[key] == null ? '' : ext[key]).toLowerCase() === 'true';
|
|
209
|
+
out.supportV2 = read(heartbeatExtIsSupportV2);
|
|
210
|
+
out.subChange = read(heartbeatExtIsSubChange);
|
|
211
|
+
return out;
|
|
212
|
+
}
|
|
213
|
+
// A UTF-16 code-unit string hash kept in signed 32-bit range. The heartbeat
|
|
214
|
+
// fingerprint must use THIS hash and not a JS-number hash: charCodeAt yields code
|
|
215
|
+
// units, which is exactly what the 31-multiplier walk iterates over.
|
|
216
|
+
export function javaStringHash(text) {
|
|
217
|
+
let h = 0;
|
|
218
|
+
for (let i = 0; i < text.length; i++) {
|
|
219
|
+
h = (Math.imul(31, h) + text.charCodeAt(i)) | 0;
|
|
220
|
+
}
|
|
221
|
+
return h;
|
|
222
|
+
}
|
|
223
|
+
export default {
|
|
224
|
+
HeartbeatData, ConsumerData, ProducerData, heartbeatDataEncode, heartbeatDataDecode,
|
|
225
|
+
ConsumeType, MessageModel, ConsumeFromWhere,
|
|
226
|
+
heartbeatExtIsSupportV2, heartbeatExtIsSubChange, decodeHeartbeatV2Flags, javaStringHash,
|
|
227
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const NAMESPACE_SEPARATOR = "%";
|
|
2
|
+
export declare class NamespaceUtil {
|
|
3
|
+
static withOutRetryAndDLQ(resource: string): string;
|
|
4
|
+
static isRetryTopic(resource: string): boolean;
|
|
5
|
+
static isDlqTopic(resource: string): boolean;
|
|
6
|
+
static isSystemResource(resource: string): boolean;
|
|
7
|
+
static isAlreadyWithNamespace(resource: string, namespace: string): boolean;
|
|
8
|
+
static withoutNamespace(resourceWithNamespace: string, namespace?: string): string;
|
|
9
|
+
static wrapNamespace(namespace: string, resourceWithoutNamespace: string): string;
|
|
10
|
+
static wrapNamespaceAndRetry(namespace: string, consumerGroup: string): string;
|
|
11
|
+
static getNamespaceFromResource(resource: string): string;
|
|
12
|
+
static getRV(resource: string, namespace: string): string;
|
|
13
|
+
}
|
|
14
|
+
export default NamespaceUtil;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// -*- coding: utf-8 -*-
|
|
2
|
+
// Namespace utility functions: namespace prefix (delimiter %) and retry/DLQ prefixed resource-name handling.
|
|
3
|
+
import { MixAll } from "../common/mixAll.js";
|
|
4
|
+
export const NAMESPACE_SEPARATOR = '%';
|
|
5
|
+
export class NamespaceUtil {
|
|
6
|
+
// Strip the retry/DLQ prefix from a resource name.
|
|
7
|
+
static withOutRetryAndDLQ(resource) {
|
|
8
|
+
return MixAll.resetRetryAndDlqTopic(resource);
|
|
9
|
+
}
|
|
10
|
+
static isRetryTopic(resource) {
|
|
11
|
+
return MixAll.isRetryTopic(resource);
|
|
12
|
+
}
|
|
13
|
+
static isDlqTopic(resource) {
|
|
14
|
+
return MixAll.isDlqTopic(resource);
|
|
15
|
+
}
|
|
16
|
+
static isSystemResource(resource) {
|
|
17
|
+
if (!resource)
|
|
18
|
+
return false;
|
|
19
|
+
return MixAll.isSysTopic(resource) || MixAll.isSysConsumerGroup(resource);
|
|
20
|
+
}
|
|
21
|
+
static isAlreadyWithNamespace(resource, namespace) {
|
|
22
|
+
if (!namespace || !resource || NamespaceUtil.isSystemResource(resource))
|
|
23
|
+
return false;
|
|
24
|
+
const plain = NamespaceUtil.withOutRetryAndDLQ(resource);
|
|
25
|
+
return plain.startsWith(namespace + NAMESPACE_SEPARATOR);
|
|
26
|
+
}
|
|
27
|
+
// Strip the namespace prefix. NS%Topic -> Topic; %RETRY%NS%GID -> %RETRY%GID.
|
|
28
|
+
static withoutNamespace(resourceWithNamespace, namespace = '') {
|
|
29
|
+
if (!resourceWithNamespace)
|
|
30
|
+
return resourceWithNamespace;
|
|
31
|
+
if (namespace) {
|
|
32
|
+
const plain = NamespaceUtil.withOutRetryAndDLQ(resourceWithNamespace);
|
|
33
|
+
if (!plain.startsWith(namespace + NAMESPACE_SEPARATOR))
|
|
34
|
+
return resourceWithNamespace;
|
|
35
|
+
}
|
|
36
|
+
else if (NamespaceUtil.isSystemResource(resourceWithNamespace)) {
|
|
37
|
+
return resourceWithNamespace;
|
|
38
|
+
}
|
|
39
|
+
let prefix = '';
|
|
40
|
+
if (NamespaceUtil.isRetryTopic(resourceWithNamespace))
|
|
41
|
+
prefix = MixAll.RETRY_GROUP_TOPIC_PREFIX;
|
|
42
|
+
if (NamespaceUtil.isDlqTopic(resourceWithNamespace))
|
|
43
|
+
prefix = MixAll.DLQ_GROUP_TOPIC_PREFIX;
|
|
44
|
+
const plain = NamespaceUtil.withOutRetryAndDLQ(resourceWithNamespace);
|
|
45
|
+
const index = plain.indexOf(NAMESPACE_SEPARATOR);
|
|
46
|
+
if (index > 0)
|
|
47
|
+
return prefix + plain.substring(index + 1);
|
|
48
|
+
return resourceWithNamespace;
|
|
49
|
+
}
|
|
50
|
+
// Prepend the namespace prefix.
|
|
51
|
+
static wrapNamespace(namespace, resourceWithoutNamespace) {
|
|
52
|
+
if (!namespace || !resourceWithoutNamespace)
|
|
53
|
+
return resourceWithoutNamespace;
|
|
54
|
+
if (NamespaceUtil.isSystemResource(resourceWithoutNamespace))
|
|
55
|
+
return resourceWithoutNamespace;
|
|
56
|
+
if (NamespaceUtil.isAlreadyWithNamespace(resourceWithoutNamespace, namespace))
|
|
57
|
+
return resourceWithoutNamespace;
|
|
58
|
+
let prefix = '';
|
|
59
|
+
if (NamespaceUtil.isRetryTopic(resourceWithoutNamespace))
|
|
60
|
+
prefix = MixAll.RETRY_GROUP_TOPIC_PREFIX;
|
|
61
|
+
if (NamespaceUtil.isDlqTopic(resourceWithoutNamespace))
|
|
62
|
+
prefix = MixAll.DLQ_GROUP_TOPIC_PREFIX;
|
|
63
|
+
const plain = NamespaceUtil.withOutRetryAndDLQ(resourceWithoutNamespace);
|
|
64
|
+
return `${prefix}${namespace}${NAMESPACE_SEPARATOR}${plain}`;
|
|
65
|
+
}
|
|
66
|
+
// %RETRY%<wrapNamespace(namespace, group)>
|
|
67
|
+
static wrapNamespaceAndRetry(namespace, consumerGroup) {
|
|
68
|
+
if (!consumerGroup)
|
|
69
|
+
return consumerGroup;
|
|
70
|
+
return MixAll.RETRY_GROUP_TOPIC_PREFIX + NamespaceUtil.wrapNamespace(namespace, consumerGroup);
|
|
71
|
+
}
|
|
72
|
+
// Extract the embedded namespace from a resource name.
|
|
73
|
+
static getNamespaceFromResource(resource) {
|
|
74
|
+
if (!resource || NamespaceUtil.isSystemResource(resource))
|
|
75
|
+
return '';
|
|
76
|
+
const plain = NamespaceUtil.withOutRetryAndDLQ(resource);
|
|
77
|
+
const index = plain.indexOf(NAMESPACE_SEPARATOR);
|
|
78
|
+
return index > 0 ? plain.substring(0, index) : '';
|
|
79
|
+
}
|
|
80
|
+
// getRV: get the resource value without its namespace (alias used by some callers).
|
|
81
|
+
static getRV(resource, namespace) {
|
|
82
|
+
return NamespaceUtil.withoutNamespace(resource, namespace);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
export default NamespaceUtil;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export declare const MESSAGE_REQUEST_MODE_PULL = "PULL";
|
|
2
|
+
export declare const MESSAGE_REQUEST_MODE_POP = "POP";
|
|
3
|
+
export declare class SetMessageRequestModeRequestBody {
|
|
4
|
+
topic: string;
|
|
5
|
+
consumerGroup: string;
|
|
6
|
+
mode: string;
|
|
7
|
+
popShareQueueNum: number;
|
|
8
|
+
toDict(): Record<string, any>;
|
|
9
|
+
encode(): Buffer;
|
|
10
|
+
}
|
|
11
|
+
export declare class BitSet {
|
|
12
|
+
bytes: Uint8Array | null;
|
|
13
|
+
set(bitIndex: number): void;
|
|
14
|
+
popCount(): number;
|
|
15
|
+
encodeBase64(): string;
|
|
16
|
+
decodeBase64(encoded: string): void;
|
|
17
|
+
}
|
|
18
|
+
export declare class BatchAck {
|
|
19
|
+
consumerGroup: string;
|
|
20
|
+
topic: string;
|
|
21
|
+
retry: string;
|
|
22
|
+
startOffset: number;
|
|
23
|
+
queueId: number;
|
|
24
|
+
reviveQueueId: number;
|
|
25
|
+
popTime: number;
|
|
26
|
+
invisibleTime: number;
|
|
27
|
+
bitSet: BitSet;
|
|
28
|
+
toDict(): Record<string, any>;
|
|
29
|
+
}
|
|
30
|
+
export declare class BatchAckMessageRequestBody {
|
|
31
|
+
brokerName: string;
|
|
32
|
+
acks: BatchAck[];
|
|
33
|
+
toDict(): Record<string, any>;
|
|
34
|
+
encode(): Buffer;
|
|
35
|
+
}
|
|
36
|
+
export declare function buildBatchAckMessageRequestBody(topic: string, consumerGroup: string, extraInfos: string[]): BatchAckMessageRequestBody;
|
|
37
|
+
export declare class QueryAssignmentRequestBody {
|
|
38
|
+
topic: string;
|
|
39
|
+
consumerGroup: string;
|
|
40
|
+
clientId: string;
|
|
41
|
+
messageModel: string;
|
|
42
|
+
strategyName: string;
|
|
43
|
+
extraInfo: string;
|
|
44
|
+
toDict(): Record<string, any>;
|
|
45
|
+
encode(): Buffer;
|
|
46
|
+
}
|
|
47
|
+
export declare class MessageQueueAssignment {
|
|
48
|
+
mq: {
|
|
49
|
+
topic: string;
|
|
50
|
+
brokerName: string;
|
|
51
|
+
queueId: number;
|
|
52
|
+
};
|
|
53
|
+
mode: string;
|
|
54
|
+
constructor(topic: string, brokerName: string, queueId: number, mode: string);
|
|
55
|
+
}
|
|
56
|
+
export declare class QueryAssignmentResponseBody {
|
|
57
|
+
static decode(body: Buffer | null): Array<MessageQueueAssignment> | null;
|
|
58
|
+
}
|