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,288 @@
|
|
|
1
|
+
import { MessageQueue } from "../common/message.js";
|
|
2
|
+
import { MixAll } from "../common/mixAll.js";
|
|
3
|
+
import { PermName } from "../common/sysflag.js";
|
|
4
|
+
import { RemotingSerializable } from "./serialize.js";
|
|
5
|
+
import { topicRouteData2EndpointsForStaticTopic } from "./static_topic.js";
|
|
6
|
+
export class QueueData {
|
|
7
|
+
brokerName;
|
|
8
|
+
readQueueNums;
|
|
9
|
+
writeQueueNums;
|
|
10
|
+
perm;
|
|
11
|
+
topicSysFlag;
|
|
12
|
+
constructor(brokerName = '', readQueueNums = 0, writeQueueNums = 0, perm = 0, topicSysFlag = 0) {
|
|
13
|
+
this.brokerName = brokerName;
|
|
14
|
+
this.readQueueNums = readQueueNums;
|
|
15
|
+
this.writeQueueNums = writeQueueNums;
|
|
16
|
+
this.perm = perm;
|
|
17
|
+
this.topicSysFlag = topicSysFlag;
|
|
18
|
+
}
|
|
19
|
+
clone() {
|
|
20
|
+
return new QueueData(this.brokerName, this.readQueueNums, this.writeQueueNums, this.perm, this.topicSysFlag);
|
|
21
|
+
}
|
|
22
|
+
toDict() {
|
|
23
|
+
return {
|
|
24
|
+
brokerName: this.brokerName,
|
|
25
|
+
readQueueNums: this.readQueueNums,
|
|
26
|
+
writeQueueNums: this.writeQueueNums,
|
|
27
|
+
perm: this.perm,
|
|
28
|
+
topicSysFlag: this.topicSysFlag,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
static fromDict(d) {
|
|
32
|
+
return new QueueData(d['brokerName'] != null ? d['brokerName'] : '', parseInt(d['readQueueNums'] != null ? d['readQueueNums'] : 0, 10), parseInt(d['writeQueueNums'] != null ? d['writeQueueNums'] : 0, 10), parseInt(d['perm'] != null ? d['perm'] : 0, 10), parseInt(d['topicSysFlag'] != null ? d['topicSysFlag'] : 0, 10));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export class BrokerData {
|
|
36
|
+
cluster;
|
|
37
|
+
brokerName;
|
|
38
|
+
brokerAddrs;
|
|
39
|
+
zoneName;
|
|
40
|
+
enableActingMaster;
|
|
41
|
+
constructor(cluster = '', brokerName = '', brokerAddrs = null, zoneName = '') {
|
|
42
|
+
this.cluster = cluster;
|
|
43
|
+
this.brokerName = brokerName;
|
|
44
|
+
this.brokerAddrs = brokerAddrs != null ? brokerAddrs : {};
|
|
45
|
+
this.zoneName = zoneName;
|
|
46
|
+
this.enableActingMaster = false;
|
|
47
|
+
}
|
|
48
|
+
selectBrokerAddr() {
|
|
49
|
+
if (!this.brokerAddrs || Object.keys(this.brokerAddrs).length === 0)
|
|
50
|
+
return null;
|
|
51
|
+
const master = this.brokerAddrs[0];
|
|
52
|
+
if (master != null)
|
|
53
|
+
return master;
|
|
54
|
+
const vals = Object.values(this.brokerAddrs);
|
|
55
|
+
return vals.length ? vals[Math.floor(Math.random() * vals.length)] : null;
|
|
56
|
+
}
|
|
57
|
+
clone() {
|
|
58
|
+
return new BrokerData(this.cluster, this.brokerName, Object.assign({}, this.brokerAddrs), this.zoneName);
|
|
59
|
+
}
|
|
60
|
+
toDict() {
|
|
61
|
+
const addrs = {};
|
|
62
|
+
for (const [k, v] of Object.entries(this.brokerAddrs))
|
|
63
|
+
addrs[String(k)] = v;
|
|
64
|
+
return {
|
|
65
|
+
cluster: this.cluster,
|
|
66
|
+
brokerName: this.brokerName,
|
|
67
|
+
brokerAddrs: addrs,
|
|
68
|
+
zoneName: this.zoneName,
|
|
69
|
+
enableActingMaster: this.enableActingMaster,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
static fromDict(d) {
|
|
73
|
+
const raw = d['brokerAddrs'] || {};
|
|
74
|
+
const addrs = {};
|
|
75
|
+
for (const [k, v] of Object.entries(raw))
|
|
76
|
+
addrs[parseInt(k, 10)] = v;
|
|
77
|
+
const bd = new BrokerData(d['cluster'] != null ? d['cluster'] : '', d['brokerName'] != null ? d['brokerName'] : '', addrs, d['zoneName'] != null ? d['zoneName'] : '');
|
|
78
|
+
bd.enableActingMaster = d['enableActingMaster'] === true;
|
|
79
|
+
return bd;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export class TopicRouteData {
|
|
83
|
+
orderTopicConf;
|
|
84
|
+
queueDatas;
|
|
85
|
+
brokerDatas;
|
|
86
|
+
filterServerTable;
|
|
87
|
+
topicQueueMappingByBroker;
|
|
88
|
+
constructor() {
|
|
89
|
+
this.orderTopicConf = null;
|
|
90
|
+
this.queueDatas = [];
|
|
91
|
+
this.brokerDatas = [];
|
|
92
|
+
this.filterServerTable = {};
|
|
93
|
+
this.topicQueueMappingByBroker = null;
|
|
94
|
+
}
|
|
95
|
+
getAllMessageQueue(topic = '') {
|
|
96
|
+
const hasMapping = this.topicQueueMappingByBroker != null
|
|
97
|
+
&& Object.keys(this.topicQueueMappingByBroker).length > 0;
|
|
98
|
+
if ((this.orderTopicConf == null || this.orderTopicConf.length === 0) && hasMapping) {
|
|
99
|
+
const mqs = Array.from(topicRouteData2EndpointsForStaticTopic(topic, this).keys());
|
|
100
|
+
mqs.sort((a, b) => a.queueId - b.queueId);
|
|
101
|
+
return mqs;
|
|
102
|
+
}
|
|
103
|
+
const mqs = [];
|
|
104
|
+
for (const qd of this.queueDatas) {
|
|
105
|
+
if (!PermName.checkPerm(qd.perm, PermName.PERM_WRITE))
|
|
106
|
+
continue;
|
|
107
|
+
let brokerData = null;
|
|
108
|
+
for (const bd of this.brokerDatas) {
|
|
109
|
+
if (bd.brokerName === qd.brokerName) {
|
|
110
|
+
brokerData = bd;
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (brokerData == null)
|
|
115
|
+
continue;
|
|
116
|
+
if (!(MixAll.MASTER_ID in brokerData.brokerAddrs))
|
|
117
|
+
continue;
|
|
118
|
+
for (let i = 0; i < qd.writeQueueNums; i++)
|
|
119
|
+
mqs.push(new MessageQueue(topic, qd.brokerName, i));
|
|
120
|
+
}
|
|
121
|
+
return mqs;
|
|
122
|
+
}
|
|
123
|
+
// Assemble all readable MessageQueues (subscribe side): read perm, no master
|
|
124
|
+
// required.
|
|
125
|
+
// Static-topic branch: with a mapping present the subscribe set is the
|
|
126
|
+
// logical endpoints key set, regardless of queueDatas.
|
|
127
|
+
getAllSubscribeMessageQueue(topic = '') {
|
|
128
|
+
const hasMapping = this.topicQueueMappingByBroker != null
|
|
129
|
+
&& Object.keys(this.topicQueueMappingByBroker).length > 0;
|
|
130
|
+
if (hasMapping) {
|
|
131
|
+
return Array.from(topicRouteData2EndpointsForStaticTopic(topic, this).keys());
|
|
132
|
+
}
|
|
133
|
+
const mqs = [];
|
|
134
|
+
for (const qd of this.queueDatas) {
|
|
135
|
+
if (!PermName.checkPerm(qd.perm, PermName.PERM_READ))
|
|
136
|
+
continue;
|
|
137
|
+
for (let i = 0; i < qd.readQueueNums; i++)
|
|
138
|
+
mqs.push(new MessageQueue(topic, qd.brokerName, i));
|
|
139
|
+
}
|
|
140
|
+
return mqs;
|
|
141
|
+
}
|
|
142
|
+
getStaticTopicEndPoints(topic) {
|
|
143
|
+
const hasMapping = this.topicQueueMappingByBroker != null
|
|
144
|
+
&& Object.keys(this.topicQueueMappingByBroker).length > 0;
|
|
145
|
+
if (!hasMapping)
|
|
146
|
+
return null;
|
|
147
|
+
const endpoints = topicRouteData2EndpointsForStaticTopic(topic, this);
|
|
148
|
+
return endpoints.size > 0 ? endpoints : null;
|
|
149
|
+
}
|
|
150
|
+
cloneTopicRouteData() {
|
|
151
|
+
const trd = new TopicRouteData();
|
|
152
|
+
trd.orderTopicConf = this.orderTopicConf;
|
|
153
|
+
trd.queueDatas = this.queueDatas.slice();
|
|
154
|
+
trd.brokerDatas = this.brokerDatas.slice();
|
|
155
|
+
const fst = {};
|
|
156
|
+
for (const [k, v] of Object.entries(this.filterServerTable))
|
|
157
|
+
fst[k] = v.slice();
|
|
158
|
+
trd.filterServerTable = fst;
|
|
159
|
+
if (this.topicQueueMappingByBroker != null)
|
|
160
|
+
trd.topicQueueMappingByBroker = Object.assign({}, this.topicQueueMappingByBroker);
|
|
161
|
+
return trd;
|
|
162
|
+
}
|
|
163
|
+
topicRouteDataChanged(old) {
|
|
164
|
+
if (old == null)
|
|
165
|
+
return true;
|
|
166
|
+
const sortQ = (a, b) => a.brokerName.localeCompare(b.brokerName) ||
|
|
167
|
+
a.readQueueNums - b.readQueueNums ||
|
|
168
|
+
a.writeQueueNums - b.writeQueueNums ||
|
|
169
|
+
a.perm - b.perm;
|
|
170
|
+
const sortB = (a, b) => a.brokerName.localeCompare(b.brokerName);
|
|
171
|
+
const oldQ = this.queueDatas.slice().sort(sortQ);
|
|
172
|
+
const newQ = old.queueDatas.slice().sort(sortQ);
|
|
173
|
+
const oldB = this.brokerDatas.slice().sort(sortB);
|
|
174
|
+
const newB = old.brokerDatas.slice().sort(sortB);
|
|
175
|
+
return !(JSON.stringify(oldQ) === JSON.stringify(newQ) && JSON.stringify(oldB) === JSON.stringify(newB));
|
|
176
|
+
}
|
|
177
|
+
toDict() {
|
|
178
|
+
const d = {
|
|
179
|
+
orderTopicConf: this.orderTopicConf,
|
|
180
|
+
queueDatas: this.queueDatas.map((q) => q.toDict()),
|
|
181
|
+
brokerDatas: this.brokerDatas.map((b) => b.toDict()),
|
|
182
|
+
filterServerTable: this.filterServerTable,
|
|
183
|
+
};
|
|
184
|
+
if (this.topicQueueMappingByBroker != null)
|
|
185
|
+
d['topicQueueMappingByBroker'] = this.topicQueueMappingByBroker;
|
|
186
|
+
return d;
|
|
187
|
+
}
|
|
188
|
+
static fromDict(d) {
|
|
189
|
+
const trd = new TopicRouteData();
|
|
190
|
+
trd.orderTopicConf = d['orderTopicConf'] != null ? d['orderTopicConf'] : null;
|
|
191
|
+
trd.queueDatas = (d['queueDatas'] || []).map((q) => QueueData.fromDict(q));
|
|
192
|
+
trd.brokerDatas = (d['brokerDatas'] || []).map((b) => BrokerData.fromDict(b));
|
|
193
|
+
const fst = {};
|
|
194
|
+
for (const [k, v] of Object.entries(d['filterServerTable'] || {}))
|
|
195
|
+
fst[k] = v.slice();
|
|
196
|
+
trd.filterServerTable = fst;
|
|
197
|
+
trd.topicQueueMappingByBroker = d['topicQueueMappingByBroker'] != null ? d['topicQueueMappingByBroker'] : null;
|
|
198
|
+
return trd;
|
|
199
|
+
}
|
|
200
|
+
encode() {
|
|
201
|
+
const data = RemotingSerializable.encode(this.toDict());
|
|
202
|
+
return data != null ? data : Buffer.alloc(0);
|
|
203
|
+
}
|
|
204
|
+
static decode(data) {
|
|
205
|
+
return TopicRouteData.fromDict(RemotingSerializable.decode(data));
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
// ---------------------------------------------------------------------------
|
|
209
|
+
// TopicRouteData helper functions.
|
|
210
|
+
// ---------------------------------------------------------------------------
|
|
211
|
+
// Map<brokerName, Map<brokerId, addr>>.
|
|
212
|
+
export function brokerDataList2Map(bdList) {
|
|
213
|
+
const map = {};
|
|
214
|
+
if (bdList != null) {
|
|
215
|
+
for (const bd of bdList) {
|
|
216
|
+
map[bd.brokerName] = Object.assign({}, bd.brokerAddrs);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return map;
|
|
220
|
+
}
|
|
221
|
+
export function brokerData2Json(bd) {
|
|
222
|
+
return RemotingSerializable.toJson(bd.toDict());
|
|
223
|
+
}
|
|
224
|
+
export function topicRouteData2TopicRouteDataJson(trd) {
|
|
225
|
+
return RemotingSerializable.toJson(trd.toDict());
|
|
226
|
+
}
|
|
227
|
+
// Find the master (brokerId 0) address for a broker within the route.
|
|
228
|
+
export function findBrokerAddressInPublish(brokerName, trd) {
|
|
229
|
+
if (!brokerName)
|
|
230
|
+
return null;
|
|
231
|
+
const map = brokerDataList2Map(trd.brokerDatas)[brokerName];
|
|
232
|
+
if (map)
|
|
233
|
+
return map[MixAll.MASTER_ID] != null ? map[MixAll.MASTER_ID] : null;
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
export function findBrokerAddressInSubscribe(brokerName, brokerId, onlyThisBroker, trd) {
|
|
237
|
+
if (!brokerName || brokerName.length < 1)
|
|
238
|
+
return null;
|
|
239
|
+
const map = brokerDataList2Map(trd.brokerDatas)[brokerName];
|
|
240
|
+
if (map && Object.keys(map).length) {
|
|
241
|
+
const addr = map[brokerId];
|
|
242
|
+
if (addr != null)
|
|
243
|
+
return addr;
|
|
244
|
+
if (!onlyThisBroker) {
|
|
245
|
+
for (const [k, v] of Object.entries(map)) {
|
|
246
|
+
const kid = parseInt(k, 10);
|
|
247
|
+
if (brokerId !== MixAll.MASTER_ID) {
|
|
248
|
+
if (kid !== MixAll.MASTER_ID)
|
|
249
|
+
return v;
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
if (kid === MixAll.MASTER_ID)
|
|
253
|
+
return v;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
const firstKey = Object.keys(map)[0];
|
|
257
|
+
return firstKey != null ? map[parseInt(firstKey, 10)] : null;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return null;
|
|
261
|
+
}
|
|
262
|
+
export function findBrokerAddressInNotRepeat(brokerName, trd) {
|
|
263
|
+
if (!brokerName)
|
|
264
|
+
return null;
|
|
265
|
+
const map = brokerDataList2Map(trd.brokerDatas)[brokerName];
|
|
266
|
+
if (map && Object.keys(map).length) {
|
|
267
|
+
const master = map[MixAll.MASTER_ID];
|
|
268
|
+
if (master != null)
|
|
269
|
+
return master;
|
|
270
|
+
const firstKey = Object.keys(map)[0];
|
|
271
|
+
return firstKey != null ? map[parseInt(firstKey, 10)] : null;
|
|
272
|
+
}
|
|
273
|
+
return null;
|
|
274
|
+
}
|
|
275
|
+
// A broker is "deployed in container" when its master address has no host:port
|
|
276
|
+
// (it is referenced by a service/DNS name rather than an IP).
|
|
277
|
+
export function brokerDeployInContainer(brokerName, trd) {
|
|
278
|
+
if (brokerName != null && trd != null) {
|
|
279
|
+
for (const bd of trd.brokerDatas) {
|
|
280
|
+
if (brokerName === bd.brokerName) {
|
|
281
|
+
const addr = bd.brokerAddrs[MixAll.MASTER_ID];
|
|
282
|
+
return addr != null && addr.indexOf(':') < 0;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return false;
|
|
287
|
+
}
|
|
288
|
+
export default { QueueData, BrokerData, TopicRouteData, brokerDataList2Map, brokerData2Json, topicRouteData2TopicRouteDataJson, findBrokerAddressInPublish, findBrokerAddressInSubscribe, findBrokerAddressInNotRepeat, brokerDeployInContainer };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { RemotingCommand } from './remotingCommand.js';
|
|
2
|
+
export interface RpcHook {
|
|
3
|
+
doBeforeRequest(addr: string, cmd: RemotingCommand): void;
|
|
4
|
+
doAfterResponse(addr: string, request: RemotingCommand | null, response: RemotingCommand | null): void;
|
|
5
|
+
}
|
|
6
|
+
export declare class NamespaceRpcHook implements RpcHook {
|
|
7
|
+
private readonly namespaceV2Provider;
|
|
8
|
+
constructor(namespaceV2: string | null | undefined | (() => string | null | undefined));
|
|
9
|
+
doBeforeRequest(_addr: string, cmd: RemotingCommand): void;
|
|
10
|
+
doAfterResponse(_addr: string, _request: RemotingCommand | null, _response: RemotingCommand | null): void;
|
|
11
|
+
}
|
|
12
|
+
export declare class StreamTypeRPCHook implements RpcHook {
|
|
13
|
+
doBeforeRequest(_addr: string, cmd: RemotingCommand): void;
|
|
14
|
+
doAfterResponse(_addr: string, _request: RemotingCommand | null, _response: RemotingCommand | null): void;
|
|
15
|
+
}
|
|
16
|
+
export interface RpcHookChainOptions {
|
|
17
|
+
namespaceV2?: string | null | (() => string | null | undefined);
|
|
18
|
+
enableStreamRequestType?: boolean;
|
|
19
|
+
userHook?: RpcHook | null;
|
|
20
|
+
}
|
|
21
|
+
export declare function buildRpcHooks(opts?: RpcHookChainOptions): RpcHook[];
|
|
22
|
+
export declare function registerRpcHooks(rc: {
|
|
23
|
+
registerRpcHook(hook: any): void;
|
|
24
|
+
}, opts?: RpcHookChainOptions): RpcHook[];
|
|
25
|
+
declare const _default: {
|
|
26
|
+
NamespaceRpcHook: typeof NamespaceRpcHook;
|
|
27
|
+
StreamTypeRPCHook: typeof StreamTypeRPCHook;
|
|
28
|
+
buildRpcHooks: typeof buildRpcHooks;
|
|
29
|
+
registerRpcHooks: typeof registerRpcHooks;
|
|
30
|
+
};
|
|
31
|
+
export default _default;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// -*- coding: utf-8 -*-
|
|
2
|
+
// Infrastructure RPC hooks and their registration order.
|
|
3
|
+
//
|
|
4
|
+
// The registration order is a load-bearing constraint (the classic remoting
|
|
5
|
+
// protocol's client-side convention):
|
|
6
|
+
//
|
|
7
|
+
// 1. Namespace hook (writes the nsd/ns fields)
|
|
8
|
+
// 2. StreamType hook (registered only when the stream request type is enabled)
|
|
9
|
+
// 3. User hooks (for example ACL signing)
|
|
10
|
+
// 4. Dynamic extended-field hooks
|
|
11
|
+
//
|
|
12
|
+
// Hooks run in registration order, and ACL signing only covers the extFields
|
|
13
|
+
// that already exist when it executes, so the namespace (and ReqT) fields must be
|
|
14
|
+
// written before the ACL hook — otherwise the broker sees unsigned fields and
|
|
15
|
+
// rejects the request ("reserve field signature").
|
|
16
|
+
import { MixAll } from "../common/mixAll.js";
|
|
17
|
+
// NamespaceRpcHook: when namespace-v2 is configured (an Alibaba-Cloud-style
|
|
18
|
+
// serverless instance id), every request carries
|
|
19
|
+
//
|
|
20
|
+
// nsd = "true", ns = <namespaceV2>
|
|
21
|
+
//
|
|
22
|
+
// This is the server-side namespace mechanism (the broker parses the real topic
|
|
23
|
+
// from the request header) — a different mechanism from the classic `namespace`
|
|
24
|
+
// field (which rewrites resource names on the client side).
|
|
25
|
+
export class NamespaceRpcHook {
|
|
26
|
+
// namespaceV2 is re-read on every request; the provider function keeps that
|
|
27
|
+
// freshness (plain strings are also accepted and behave as a snapshot).
|
|
28
|
+
namespaceV2Provider;
|
|
29
|
+
constructor(namespaceV2) {
|
|
30
|
+
this.namespaceV2Provider = typeof namespaceV2 === 'function' ? namespaceV2 : () => namespaceV2;
|
|
31
|
+
}
|
|
32
|
+
doBeforeRequest(_addr, cmd) {
|
|
33
|
+
const ns = this.namespaceV2Provider();
|
|
34
|
+
// Empty-value guard: with no namespace configured the request's extFields must
|
|
35
|
+
// stay untouched — the hook adds nothing.
|
|
36
|
+
if (ns == null || ns === '')
|
|
37
|
+
return;
|
|
38
|
+
cmd.addExtField(MixAll.RPC_REQUEST_HEADER_NAMESPACED_FIELD, 'true');
|
|
39
|
+
cmd.addExtField(MixAll.RPC_REQUEST_HEADER_NAMESPACE_FIELD, ns);
|
|
40
|
+
}
|
|
41
|
+
// doAfterResponse is a no-op.
|
|
42
|
+
doAfterResponse(_addr, _request, _response) { }
|
|
43
|
+
}
|
|
44
|
+
// StreamTypeRPCHook: stamps ReqT = RequestType.STREAM, whose enum code is 0, so
|
|
45
|
+
// the field falls inside the ACL signing coverage (this hook registers before
|
|
46
|
+
// the user hooks).
|
|
47
|
+
export class StreamTypeRPCHook {
|
|
48
|
+
doBeforeRequest(_addr, cmd) {
|
|
49
|
+
cmd.addExtField(MixAll.REQ_T, '0');
|
|
50
|
+
}
|
|
51
|
+
doAfterResponse(_addr, _request, _response) { }
|
|
52
|
+
}
|
|
53
|
+
// buildRpcHooks returns the hook chain in the conventional order:
|
|
54
|
+
// Namespace -> Stream (only when enabled) -> user hooks.
|
|
55
|
+
// The Namespace hook is always installed and is a no-op when namespaceV2 is empty.
|
|
56
|
+
export function buildRpcHooks(opts = {}) {
|
|
57
|
+
const hooks = [];
|
|
58
|
+
hooks.push(new NamespaceRpcHook(opts.namespaceV2 != null ? opts.namespaceV2 : null));
|
|
59
|
+
if (opts.enableStreamRequestType === true)
|
|
60
|
+
hooks.push(new StreamTypeRPCHook());
|
|
61
|
+
if (opts.userHook != null)
|
|
62
|
+
hooks.push(opts.userHook);
|
|
63
|
+
return hooks;
|
|
64
|
+
}
|
|
65
|
+
// registerRpcHooks installs the hook chain on the RemotingClient in the above
|
|
66
|
+
// order and returns it (tests assert that order).
|
|
67
|
+
export function registerRpcHooks(rc, opts = {}) {
|
|
68
|
+
const hooks = buildRpcHooks(opts);
|
|
69
|
+
for (const hook of hooks)
|
|
70
|
+
rc.registerRpcHook(hook);
|
|
71
|
+
return hooks;
|
|
72
|
+
}
|
|
73
|
+
export default { NamespaceRpcHook, StreamTypeRPCHook, buildRpcHooks, registerRpcHooks };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export declare function fastjsonLoads(text: any): {};
|
|
2
|
+
export declare function decodeMessageQueueKey(key: any): {};
|
|
3
|
+
export declare class RemotingSerializable {
|
|
4
|
+
static encode(obj: any): any;
|
|
5
|
+
static toJson(obj: any, pretty?: boolean): string;
|
|
6
|
+
static decode(data: any): any;
|
|
7
|
+
static fromJson(jsonStr: any): any;
|
|
8
|
+
static decodeJson(data: any): any;
|
|
9
|
+
}
|
|
10
|
+
export declare class RocketMQSerializable {
|
|
11
|
+
static writeStr(buf: any, offset: any, useShortLength: any, s: any): any;
|
|
12
|
+
static readStr(buf: any, offset: any, useShortLength: any): any[];
|
|
13
|
+
static mapSerialize(mapData: any): any;
|
|
14
|
+
static calTotalLen(remark: any, ext: any): any;
|
|
15
|
+
static rocketMqProtocolEncode(cmd: any): any;
|
|
16
|
+
static mapDeserialize(buf: any, offset: any, length: any): any[];
|
|
17
|
+
static rocketMqProtocolDecode(headerBytes: any): {
|
|
18
|
+
code: number;
|
|
19
|
+
language: any;
|
|
20
|
+
version: number;
|
|
21
|
+
opaque: any;
|
|
22
|
+
flag: any;
|
|
23
|
+
remark: any;
|
|
24
|
+
extFields: any;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
declare const _default: {
|
|
28
|
+
RemotingSerializable: typeof RemotingSerializable;
|
|
29
|
+
RocketMQSerializable: typeof RocketMQSerializable;
|
|
30
|
+
fastjsonLoads: typeof fastjsonLoads;
|
|
31
|
+
decodeMessageQueueKey: typeof decodeMessageQueueKey;
|
|
32
|
+
};
|
|
33
|
+
export default _default;
|