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.
Files changed (137) hide show
  1. package/README.en.md +428 -0
  2. package/README.md +424 -2
  3. package/dist/client/admin.d.ts +229 -0
  4. package/dist/client/admin.js +2462 -0
  5. package/dist/client/allocate.d.ts +48 -0
  6. package/dist/client/allocate.js +365 -0
  7. package/dist/client/backpressure.d.ts +23 -0
  8. package/dist/client/backpressure.js +95 -0
  9. package/dist/client/consumer.d.ts +294 -0
  10. package/dist/client/consumer.js +3095 -0
  11. package/dist/client/consumer_result.d.ts +129 -0
  12. package/dist/client/consumer_result.js +138 -0
  13. package/dist/client/consumer_stats.d.ts +69 -0
  14. package/dist/client/consumer_stats.js +258 -0
  15. package/dist/client/exception.d.ts +39 -0
  16. package/dist/client/exception.js +36 -0
  17. package/dist/client/hook.d.ts +145 -0
  18. package/dist/client/hook.js +171 -0
  19. package/dist/client/latency.d.ts +61 -0
  20. package/dist/client/latency.js +239 -0
  21. package/dist/client/lite_pull_consumer.d.ts +151 -0
  22. package/dist/client/lite_pull_consumer.js +1096 -0
  23. package/dist/client/mq_client.d.ts +188 -0
  24. package/dist/client/mq_client.js +1678 -0
  25. package/dist/client/mq_client_manager.d.ts +21 -0
  26. package/dist/client/mq_client_manager.js +129 -0
  27. package/dist/client/offset_store.d.ts +45 -0
  28. package/dist/client/offset_store.js +389 -0
  29. package/dist/client/open_tracing_hook.d.ts +52 -0
  30. package/dist/client/open_tracing_hook.js +241 -0
  31. package/dist/client/pop_api.d.ts +28 -0
  32. package/dist/client/pop_api.js +224 -0
  33. package/dist/client/pop_consumer.d.ts +23 -0
  34. package/dist/client/pop_consumer.js +719 -0
  35. package/dist/client/pop_process_queue.d.ts +15 -0
  36. package/dist/client/pop_process_queue.js +51 -0
  37. package/dist/client/process_queue.d.ts +49 -0
  38. package/dist/client/process_queue.js +261 -0
  39. package/dist/client/produce_accumulator.d.ts +75 -0
  40. package/dist/client/produce_accumulator.js +288 -0
  41. package/dist/client/producer.d.ts +231 -0
  42. package/dist/client/producer.js +1774 -0
  43. package/dist/client/pull_api.d.ts +26 -0
  44. package/dist/client/pull_api.js +264 -0
  45. package/dist/client/pull_consumer.d.ts +119 -0
  46. package/dist/client/pull_consumer.js +876 -0
  47. package/dist/client/pull_schedule_service.d.ts +71 -0
  48. package/dist/client/pull_schedule_service.js +424 -0
  49. package/dist/client/request_reply.d.ts +61 -0
  50. package/dist/client/request_reply.js +232 -0
  51. package/dist/client/retry_message.d.ts +2 -0
  52. package/dist/client/retry_message.js +27 -0
  53. package/dist/client/send_result.d.ts +57 -0
  54. package/dist/client/send_result.js +70 -0
  55. package/dist/client/top_addressing.d.ts +20 -0
  56. package/dist/client/top_addressing.js +75 -0
  57. package/dist/client/trace_context.d.ts +61 -0
  58. package/dist/client/trace_context.js +373 -0
  59. package/dist/client/trace_dispatcher.d.ts +31 -0
  60. package/dist/client/trace_dispatcher.js +236 -0
  61. package/dist/client/trace_hook.d.ts +23 -0
  62. package/dist/client/trace_hook.js +228 -0
  63. package/dist/client/traceparent.d.ts +9 -0
  64. package/dist/client/traceparent.js +86 -0
  65. package/dist/common/boundary_type.d.ts +7 -0
  66. package/dist/common/boundary_type.js +16 -0
  67. package/dist/common/compress.d.ts +28 -0
  68. package/dist/common/compress.js +512 -0
  69. package/dist/common/message.d.ts +129 -0
  70. package/dist/common/message.js +214 -0
  71. package/dist/common/messageClientIdSetter.d.ts +7 -0
  72. package/dist/common/messageClientIdSetter.js +48 -0
  73. package/dist/common/messageConst.d.ts +68 -0
  74. package/dist/common/messageConst.js +68 -0
  75. package/dist/common/messageDecoder.d.ts +40 -0
  76. package/dist/common/messageDecoder.js +504 -0
  77. package/dist/common/messageType.d.ts +11 -0
  78. package/dist/common/messageType.js +11 -0
  79. package/dist/common/message_accessor.d.ts +39 -0
  80. package/dist/common/message_accessor.js +135 -0
  81. package/dist/common/mixAll.d.ts +106 -0
  82. package/dist/common/mixAll.js +247 -0
  83. package/dist/common/recall_message_handle.d.ts +25 -0
  84. package/dist/common/recall_message_handle.js +98 -0
  85. package/dist/common/subscriptionData.d.ts +36 -0
  86. package/dist/common/subscriptionData.js +64 -0
  87. package/dist/common/sysflag.d.ts +129 -0
  88. package/dist/common/sysflag.js +96 -0
  89. package/dist/common/topic_config.d.ts +66 -0
  90. package/dist/common/topic_config.js +106 -0
  91. package/dist/common/topic_validator.d.ts +49 -0
  92. package/dist/common/topic_validator.js +115 -0
  93. package/dist/common/utilAll.d.ts +39 -0
  94. package/dist/common/utilAll.js +154 -0
  95. package/dist/common/validators.d.ts +25 -0
  96. package/dist/common/validators.js +80 -0
  97. package/dist/index.d.ts +24 -0
  98. package/dist/index.js +36 -0
  99. package/dist/logging.d.ts +24 -0
  100. package/dist/logging.js +246 -0
  101. package/dist/remoting/acl.d.ts +16 -0
  102. package/dist/remoting/acl.js +39 -0
  103. package/dist/remoting/admin_body.d.ts +257 -0
  104. package/dist/remoting/admin_body.js +669 -0
  105. package/dist/remoting/bodies.d.ts +475 -0
  106. package/dist/remoting/bodies.js +1131 -0
  107. package/dist/remoting/client.d.ts +73 -0
  108. package/dist/remoting/client.js +591 -0
  109. package/dist/remoting/codes.d.ts +296 -0
  110. package/dist/remoting/codes.js +301 -0
  111. package/dist/remoting/exception.d.ts +45 -0
  112. package/dist/remoting/exception.js +58 -0
  113. package/dist/remoting/extra_info.d.ts +61 -0
  114. package/dist/remoting/extra_info.js +220 -0
  115. package/dist/remoting/headers.d.ts +758 -0
  116. package/dist/remoting/headers.js +1307 -0
  117. package/dist/remoting/heartbeat.d.ts +91 -0
  118. package/dist/remoting/heartbeat.js +227 -0
  119. package/dist/remoting/namespace.d.ts +14 -0
  120. package/dist/remoting/namespace.js +85 -0
  121. package/dist/remoting/pop_bodies.d.ts +58 -0
  122. package/dist/remoting/pop_bodies.js +214 -0
  123. package/dist/remoting/remotingCommand.d.ts +39 -0
  124. package/dist/remoting/remotingCommand.js +225 -0
  125. package/dist/remoting/route.d.ts +61 -0
  126. package/dist/remoting/route.js +288 -0
  127. package/dist/remoting/rpc_hooks.d.ts +31 -0
  128. package/dist/remoting/rpc_hooks.js +73 -0
  129. package/dist/remoting/serialize.d.ts +33 -0
  130. package/dist/remoting/serialize.js +372 -0
  131. package/dist/remoting/socks_proxy.d.ts +29 -0
  132. package/dist/remoting/socks_proxy.js +379 -0
  133. package/dist/remoting/static_topic.d.ts +49 -0
  134. package/dist/remoting/static_topic.js +244 -0
  135. package/dist/remoting/subscription.d.ts +65 -0
  136. package/dist/remoting/subscription.js +172 -0
  137. package/package.json +38 -4
@@ -0,0 +1,232 @@
1
+ // -*- coding: utf-8 -*-
2
+ // Request-response support.
3
+ //
4
+ // A request producer's message carries a correlation id and a reply-to topic;
5
+ // the responder generates a reply message from them and settles the
6
+ // corresponding future. This module only maintains the in-flight future table
7
+ // and message helpers; the actual network round trip is done by the producer.
8
+ import { Message } from "../common/message.js";
9
+ import { MessageConst } from "../common/messageConst.js";
10
+ import { MessageAccessor } from "../common/message_accessor.js";
11
+ import { MixAll } from "../common/mixAll.js";
12
+ import { MQClientException } from "../remoting/exception.js";
13
+ import { getLogger } from "../logging.js";
14
+ const logger = getLogger('client.request_reply');
15
+ let _correlationSeq = 0;
16
+ export function createCorrelationId() {
17
+ _correlationSeq = (_correlationSeq + 1) & 0x7fffffff;
18
+ return `${Date.now()}${_correlationSeq.toString(16)}`;
19
+ }
20
+ export class RequestResponseFuture {
21
+ correlationId;
22
+ requestMsg;
23
+ timeoutMillis;
24
+ beginTimestamp;
25
+ done;
26
+ // The async callback (null in the synchronous form), the reply message,
27
+ // whether the request was sent, the failure cause, and the "callback runs
28
+ // exactly once" latch.
29
+ requestCallback;
30
+ responseMsg;
31
+ sendRequestOk;
32
+ cause;
33
+ _callbackExecuted;
34
+ _resolve;
35
+ _reject;
36
+ _promise;
37
+ constructor(correlationId, requestMsg, timeoutMillis, requestCallback = null) {
38
+ this.correlationId = correlationId;
39
+ this.requestMsg = requestMsg;
40
+ this.timeoutMillis = timeoutMillis;
41
+ this.beginTimestamp = Date.now();
42
+ this.done = false;
43
+ this.requestCallback = requestCallback;
44
+ this.responseMsg = null;
45
+ this.sendRequestOk = true;
46
+ this.cause = null;
47
+ this._callbackExecuted = false;
48
+ this._resolve = null;
49
+ this._reject = null;
50
+ this._promise = new Promise((resolve, reject) => {
51
+ this._resolve = resolve;
52
+ this._reject = reject;
53
+ });
54
+ }
55
+ promise() { return this._promise; }
56
+ // Stores the reply message; the latch here is carried by the promise settling, triggered by complete().
57
+ putResponseMessage(responseMsg) {
58
+ this.responseMsg = responseMsg;
59
+ }
60
+ setSendRequestOk(sendRequestOk) { this.sendRequestOk = sendRequestOk; }
61
+ setCause(cause) { this.cause = cause; }
62
+ // Fires the async callback EXACTLY ONCE: guaranteed by the _callbackExecuted
63
+ // latch — the reply-arrival path and the timeout-scan path cannot both
64
+ // deliver. onSuccess runs only when the request was sent and no cause is
65
+ // recorded; otherwise onException runs.
66
+ executeRequestCallback() {
67
+ const cb = this.requestCallback;
68
+ if (cb == null)
69
+ return;
70
+ if (this._callbackExecuted)
71
+ return;
72
+ this._callbackExecuted = true;
73
+ if (this.sendRequestOk && this.cause == null) {
74
+ if (typeof cb === 'function')
75
+ cb(this.responseMsg, null);
76
+ else
77
+ cb.onSuccess(this.responseMsg);
78
+ }
79
+ else {
80
+ const err = this.cause != null ? this.cause : new Error('request failed');
81
+ if (typeof cb === 'function')
82
+ cb(null, err);
83
+ else
84
+ cb.onException(err);
85
+ }
86
+ }
87
+ complete(replyMsg) {
88
+ if (this.done)
89
+ return;
90
+ this.done = true;
91
+ this.responseMsg = replyMsg;
92
+ if (this._resolve)
93
+ this._resolve(replyMsg);
94
+ this.executeRequestCallback();
95
+ }
96
+ completeExceptionally(err) {
97
+ if (this.done)
98
+ return;
99
+ this.done = true;
100
+ this.cause = err;
101
+ if (this._reject)
102
+ this._reject(err);
103
+ this.executeRequestCallback();
104
+ }
105
+ isDone() { return this.done; }
106
+ isTimeout() {
107
+ return Date.now() - this.beginTimestamp > this.timeoutMillis;
108
+ }
109
+ }
110
+ export class RequestFutureHolder {
111
+ static _instance = null;
112
+ table = new Map();
113
+ // TTL scan: periodically clean up timed-out requests as long as at least one producer is running (3s initial delay, 1s interval).
114
+ producerSet = new Set();
115
+ _sweepTimer = null;
116
+ static getInstance() {
117
+ if (RequestFutureHolder._instance == null) {
118
+ RequestFutureHolder._instance = new RequestFutureHolder();
119
+ }
120
+ return RequestFutureHolder._instance;
121
+ }
122
+ putRequest(correlationId, future) {
123
+ this.table.set(correlationId, future);
124
+ }
125
+ getRequest(correlationId) {
126
+ return this.table.get(correlationId) != null ? this.table.get(correlationId) : null;
127
+ }
128
+ // Take the future out and remove it from the table (once the reply arrives, tracking is no longer needed).
129
+ removeRequest(correlationId) {
130
+ const f = this.table.get(correlationId);
131
+ if (f != null)
132
+ this.table.delete(correlationId);
133
+ return f != null ? f : null;
134
+ }
135
+ // scanExpiredRequest: remove every TTL-expired future from the table first,
136
+ // then fire their callbacks uniformly with a timeout cause. REMOVE FROM
137
+ // TABLE BEFORE CALLBACK — the reply-arrival path also removes from the
138
+ // table, so removing first avoids a late reply re-delivering after the
139
+ // request was already marked failed.
140
+ scanExpiredRequest() {
141
+ const expired = [];
142
+ for (const [key, rep] of this.table.entries()) {
143
+ if (rep.isTimeout()) {
144
+ this.table.delete(key);
145
+ expired.push(rep);
146
+ logger.warning('remove timeout request, CorrelationId=%s', rep.correlationId);
147
+ }
148
+ }
149
+ for (const rf of expired) {
150
+ try {
151
+ rf.setCause(new MQClientException('request timeout, no reply message.'));
152
+ rf.executeRequestCallback();
153
+ }
154
+ catch (e) {
155
+ logger.warning('scanExpiredRequest callback error: %s', e.message);
156
+ }
157
+ }
158
+ }
159
+ // Reference-counted TTL scan: the first round runs 3s after the first producer starts, then every 1s.
160
+ startScheduledTask(producer) {
161
+ this.producerSet.add(producer);
162
+ if (this._sweepTimer == null) {
163
+ const tick = () => {
164
+ try {
165
+ this.scanExpiredRequest();
166
+ }
167
+ catch (e) { /* never break the client */ }
168
+ this._sweepTimer = setTimeout(tick, 1000);
169
+ if (typeof this._sweepTimer.unref === 'function')
170
+ this._sweepTimer.unref();
171
+ };
172
+ this._sweepTimer = setTimeout(tick, 3000);
173
+ if (typeof this._sweepTimer.unref === 'function')
174
+ this._sweepTimer.unref();
175
+ }
176
+ }
177
+ // Drop one producer reference; the TTL scan stops only when the last producer goes away.
178
+ shutdown(producer) {
179
+ this.producerSet.delete(producer);
180
+ if (this.producerSet.size <= 0 && this._sweepTimer != null) {
181
+ clearTimeout(this._sweepTimer);
182
+ this._sweepTimer = null;
183
+ }
184
+ }
185
+ size() { return this.table.size; }
186
+ }
187
+ export const REQUEST_FUTURE_HOLDER = RequestFutureHolder.getInstance();
188
+ // Build a reply message from the request message: the reply's TOPIC is 5.x's
189
+ // REPLY topic (`<cluster>_REPLY_TOPIC`, where cluster comes from the request's
190
+ // CLUSTER property, stamped in by the broker when the request arrives); the
191
+ // requester's clientId rides along via the REPLY_TO_CLIENT property, and the
192
+ // broker uses it to find the requester's channel and push 326 straight back.
193
+ // Throws when the request lacks the CLUSTER property.
194
+ export function createReplyMessage(requestMessage, body) {
195
+ const cluster = MessageAccessor.getProperty(requestMessage, MessageConst.PROPERTY_CLUSTER);
196
+ if (cluster == null || cluster === '') {
197
+ throw new MQClientException('create reply message fail, requestMessage error, property[CLUSTER] is null.');
198
+ }
199
+ const replyTo = MessageAccessor.getProperty(requestMessage, MessageConst.PROPERTY_MESSAGE_REPLY_TO_CLIENT);
200
+ const correlationId = MessageAccessor.getProperty(requestMessage, MessageConst.PROPERTY_CORRELATION_ID);
201
+ const ttl = MessageAccessor.getProperty(requestMessage, MessageConst.PROPERTY_MESSAGE_TTL);
202
+ const reply = new Message();
203
+ if (typeof body === 'string')
204
+ reply.setBody(Buffer.from(body, 'utf8'));
205
+ else
206
+ reply.setBody(body);
207
+ reply.setTopic(MixAll.getReplyTopic(cluster));
208
+ MessageAccessor.putProperty(reply, MessageConst.PROPERTY_MESSAGE_TYPE, MixAll.REPLY_MESSAGE_FLAG);
209
+ if (correlationId != null)
210
+ MessageAccessor.putProperty(reply, MessageConst.PROPERTY_CORRELATION_ID, correlationId);
211
+ if (replyTo != null)
212
+ MessageAccessor.putProperty(reply, MessageConst.PROPERTY_MESSAGE_REPLY_TO_CLIENT, replyTo);
213
+ if (ttl != null)
214
+ MessageAccessor.putProperty(reply, MessageConst.PROPERTY_MESSAGE_TTL, ttl);
215
+ return reply;
216
+ }
217
+ export function isReplyMessage(msg) {
218
+ const t = MessageAccessor.getMessageType(msg);
219
+ return t === 'Reply_Msg';
220
+ }
221
+ export class RequestCallback {
222
+ onSuccess(replyMsg) { void replyMsg; }
223
+ onException(e) { void e; }
224
+ }
225
+ // Compose the reply topic for a cluster (used by producer.request).
226
+ export function getReplyTopic(clusterName) {
227
+ return MixAll.getReplyTopic(clusterName);
228
+ }
229
+ export default {
230
+ createCorrelationId, RequestResponseFuture, RequestFutureHolder, REQUEST_FUTURE_HOLDER,
231
+ createReplyMessage, isReplyMessage, RequestCallback, getReplyTopic,
232
+ };
@@ -0,0 +1,2 @@
1
+ import { Message, MessageExt } from '../common/message.js';
2
+ export declare function buildRetryMessage(consumerGroup: string, msg: MessageExt, maxReconsumeTimes: number): Message;
@@ -0,0 +1,27 @@
1
+ // The normal message that carries a failed delivery to %RETRY%<group>.
2
+ //
3
+ // Both send-back forms share this shape: the body and properties are copied,
4
+ // the origin id falls back to the message id, the retry bookkeeping is written,
5
+ // and the half-message marker is cleared so the broker does not treat the copy
6
+ // as a transaction check-back message all over again.
7
+ import { Message } from "../common/message.js";
8
+ import { MessageConst } from "../common/messageConst.js";
9
+ import { MixAll } from "../common/mixAll.js";
10
+ import { clientMsgId } from "../common/messageClientIdSetter.js";
11
+ export function buildRetryMessage(consumerGroup, msg, maxReconsumeTimes) {
12
+ const newMsg = new Message(MixAll.getRetryTopic(consumerGroup), Buffer.from(msg.getBody() || Buffer.alloc(0)));
13
+ newMsg.setProperties({ ...(msg.getProperties() || {}) });
14
+ newMsg.setFlag(msg.getFlag());
15
+ let originMsgID = clientMsgId(msg);
16
+ const orig = msg.getProperty(MessageConst.PROPERTY_ORIGIN_MESSAGE_ID);
17
+ if (orig)
18
+ originMsgID = orig;
19
+ if (originMsgID)
20
+ newMsg.putProperty(MessageConst.PROPERTY_ORIGIN_MESSAGE_ID, originMsgID);
21
+ newMsg.putProperty(MessageConst.PROPERTY_RETRY_TOPIC, msg.getTopic());
22
+ newMsg.putProperty(MessageConst.PROPERTY_RECONSUME_TIME, String(msg.getReconsumeTimes() + 1));
23
+ newMsg.putProperty(MessageConst.PROPERTY_MAX_RECONSUME_TIMES, String(maxReconsumeTimes));
24
+ newMsg.removeProperty(MessageConst.PROPERTY_TRANSACTION_PREPARED);
25
+ newMsg.setDelayTimeLevel(3 + msg.getReconsumeTimes());
26
+ return newMsg;
27
+ }
@@ -0,0 +1,57 @@
1
+ import { MessageQueue } from '../common/message.js';
2
+ export declare const SendStatus: {
3
+ SEND_OK: number;
4
+ FLUSH_DISK_TIMEOUT: number;
5
+ FLUSH_SLAVE_TIMEOUT: number;
6
+ SLAVE_NOT_AVAILABLE: number;
7
+ fromCode(code: number): number;
8
+ };
9
+ export declare class SendResult {
10
+ sendStatus: number;
11
+ msgId: string;
12
+ messageQueue: MessageQueue | null;
13
+ queueOffset: number;
14
+ transactionId: string | null;
15
+ offsetMsgId: string | null;
16
+ regionId: string | null;
17
+ traceOn: boolean;
18
+ recallHandle: string | null;
19
+ constructor(sendStatus?: number, msgId?: string, messageQueue?: MessageQueue | null, queueOffset?: number, transactionId?: string | null, offsetMsgId?: string | null, regionId?: string | null, traceOn?: boolean, recallHandle?: string | null);
20
+ getSendStatus(): number;
21
+ setSendStatus(s: number): void;
22
+ getMsgId(): string;
23
+ setMsgId(id: string): void;
24
+ getMessageQueue(): MessageQueue | null;
25
+ setMessageQueue(mq: MessageQueue | null): void;
26
+ getQueueOffset(): number;
27
+ setQueueOffset(o: number): void;
28
+ getTransactionId(): string | null;
29
+ setTransactionId(id: string | null): void;
30
+ getOffsetMsgId(): string | null;
31
+ setOffsetMsgId(id: string | null): void;
32
+ getRegionId(): string | null;
33
+ setRegionId(r: string | null): void;
34
+ isTraceOn(): boolean;
35
+ setTraceOn(t: boolean): void;
36
+ getRecallHandle(): string | null;
37
+ setRecallHandle(h: string | null): void;
38
+ toString(): string;
39
+ }
40
+ export declare class TransactionSendResult extends SendResult {
41
+ localTransactionState: number;
42
+ constructor(sendStatus?: number, msgId?: string, messageQueue?: MessageQueue | null, queueOffset?: number, transactionId?: string | null, offsetMsgId?: string | null, regionId?: string | null, traceOn?: boolean, recallHandle?: string | null);
43
+ getLocalTransactionState(): number;
44
+ setLocalTransactionState(s: number): void;
45
+ }
46
+ declare const _default: {
47
+ SendStatus: {
48
+ SEND_OK: number;
49
+ FLUSH_DISK_TIMEOUT: number;
50
+ FLUSH_SLAVE_TIMEOUT: number;
51
+ SLAVE_NOT_AVAILABLE: number;
52
+ fromCode(code: number): number;
53
+ };
54
+ SendResult: typeof SendResult;
55
+ TransactionSendResult: typeof TransactionSendResult;
56
+ };
57
+ export default _default;
@@ -0,0 +1,70 @@
1
+ export const SendStatus = {
2
+ SEND_OK: 0,
3
+ FLUSH_DISK_TIMEOUT: 1,
4
+ FLUSH_SLAVE_TIMEOUT: 2,
5
+ SLAVE_NOT_AVAILABLE: 3,
6
+ fromCode(code) {
7
+ switch (code) {
8
+ case SendStatus.SEND_OK: return SendStatus.SEND_OK;
9
+ case SendStatus.FLUSH_DISK_TIMEOUT: return SendStatus.FLUSH_DISK_TIMEOUT;
10
+ case SendStatus.FLUSH_SLAVE_TIMEOUT: return SendStatus.FLUSH_SLAVE_TIMEOUT;
11
+ case SendStatus.SLAVE_NOT_AVAILABLE: return SendStatus.SLAVE_NOT_AVAILABLE;
12
+ default: return SendStatus.SEND_OK;
13
+ }
14
+ },
15
+ };
16
+ export class SendResult {
17
+ sendStatus;
18
+ msgId;
19
+ messageQueue;
20
+ queueOffset;
21
+ transactionId;
22
+ offsetMsgId;
23
+ regionId;
24
+ traceOn;
25
+ recallHandle;
26
+ constructor(sendStatus = SendStatus.SEND_OK, msgId = '', messageQueue = null, queueOffset = 0, transactionId = null, offsetMsgId = null, regionId = null, traceOn = true, recallHandle = null) {
27
+ this.sendStatus = sendStatus;
28
+ this.msgId = msgId;
29
+ this.messageQueue = messageQueue;
30
+ this.queueOffset = queueOffset;
31
+ this.transactionId = transactionId;
32
+ this.offsetMsgId = offsetMsgId;
33
+ this.regionId = regionId;
34
+ this.traceOn = traceOn;
35
+ this.recallHandle = recallHandle;
36
+ }
37
+ getSendStatus() { return this.sendStatus; }
38
+ setSendStatus(s) { this.sendStatus = s; }
39
+ getMsgId() { return this.msgId; }
40
+ setMsgId(id) { this.msgId = id; }
41
+ getMessageQueue() { return this.messageQueue; }
42
+ setMessageQueue(mq) { this.messageQueue = mq; }
43
+ getQueueOffset() { return this.queueOffset; }
44
+ setQueueOffset(o) { this.queueOffset = o; }
45
+ getTransactionId() { return this.transactionId; }
46
+ setTransactionId(id) { this.transactionId = id; }
47
+ getOffsetMsgId() { return this.offsetMsgId; }
48
+ setOffsetMsgId(id) { this.offsetMsgId = id; }
49
+ getRegionId() { return this.regionId; }
50
+ setRegionId(r) { this.regionId = r; }
51
+ isTraceOn() { return this.traceOn; }
52
+ setTraceOn(t) { this.traceOn = t; }
53
+ getRecallHandle() { return this.recallHandle; }
54
+ setRecallHandle(h) { this.recallHandle = h; }
55
+ toString() {
56
+ return `SendResult [sendStatus=${this.sendStatus}, msgId=${this.msgId}, ` +
57
+ `offsetMsgId=${this.offsetMsgId}, messageQueue=${this.messageQueue}, queueOffset=${this.queueOffset}, ` +
58
+ `regionId=${this.regionId}, traceOn=${this.traceOn}, recallHandle=${this.recallHandle}]`;
59
+ }
60
+ }
61
+ export class TransactionSendResult extends SendResult {
62
+ localTransactionState;
63
+ constructor(sendStatus = SendStatus.SEND_OK, msgId = '', messageQueue = null, queueOffset = 0, transactionId = null, offsetMsgId = null, regionId = null, traceOn = true, recallHandle = null) {
64
+ super(sendStatus, msgId, messageQueue, queueOffset, transactionId, offsetMsgId, regionId, traceOn, recallHandle);
65
+ this.localTransactionState = 0;
66
+ }
67
+ getLocalTransactionState() { return this.localTransactionState; }
68
+ setLocalTransactionState(s) { this.localTransactionState = s; }
69
+ }
70
+ export default { SendStatus, SendResult, TransactionSendResult };
@@ -0,0 +1,20 @@
1
+ export declare function clearNewLine(s: string | null): string | null;
2
+ export declare class DefaultTopAddressing {
3
+ wsAddr: string | null;
4
+ unitName: string | null;
5
+ private changeCallBack;
6
+ private lastAddrs;
7
+ constructor(wsAddr?: string | null, unitName?: string | null);
8
+ registerChangeCallBack(cb: (addrs: string) => string | null): void;
9
+ clearChangeCallBack(): void;
10
+ getWsAddr(domain: string | null, subgroup?: string): string | null;
11
+ buildUrl(subgroup?: string): string | null;
12
+ isConfigured(): boolean;
13
+ fetchNsAddr(subgroup?: string): Promise<string | null>;
14
+ fetchAndApply(subgroup?: string): Promise<string | null>;
15
+ }
16
+ declare const _default: {
17
+ DefaultTopAddressing: typeof DefaultTopAddressing;
18
+ clearNewLine: typeof clearNewLine;
19
+ };
20
+ export default _default;
@@ -0,0 +1,75 @@
1
+ export function clearNewLine(s) {
2
+ if (s == null)
3
+ return null;
4
+ return s.replace(/[\r\n]/g, '').trim();
5
+ }
6
+ export class DefaultTopAddressing {
7
+ wsAddr;
8
+ unitName;
9
+ // Change callback: fires when the address list returned by the HTTP endpoint DIFFERS from the one last seen.
10
+ changeCallBack = null;
11
+ lastAddrs = null;
12
+ constructor(wsAddr = null, unitName = null) {
13
+ this.wsAddr = wsAddr;
14
+ this.unitName = unitName;
15
+ }
16
+ registerChangeCallBack(cb) {
17
+ this.changeCallBack = cb;
18
+ }
19
+ clearChangeCallBack() {
20
+ this.changeCallBack = null;
21
+ }
22
+ // Domain used to build the ws url. Falls back to the ROCKETMQ_NAMESRV_DOMAIN env var.
23
+ getWsAddr(domain, subgroup = 'nsaddr') {
24
+ if (!domain)
25
+ return null;
26
+ let wsUrl = `http://${domain}:8080/rocketmq/${subgroup}`;
27
+ if (this.unitName)
28
+ wsUrl += `?unit=${this.unitName}`;
29
+ return wsUrl;
30
+ }
31
+ buildUrl(subgroup = 'nsaddr') {
32
+ const domain = this.wsAddr || process.env['ROCKETMQ_NAMESRV_DOMAIN'] || '';
33
+ if (!domain)
34
+ return null;
35
+ let wsUrl = `http://${domain}/rocketmq/${subgroup}`;
36
+ if (this.unitName)
37
+ wsUrl += `?unit=${this.unitName}`;
38
+ return wsUrl;
39
+ }
40
+ isConfigured() {
41
+ return !!process.env['ROCKETMQ_NAMESRV_DOMAIN'];
42
+ }
43
+ async fetchNsAddr(subgroup = 'nsaddr') {
44
+ const url = this.buildUrl(subgroup);
45
+ if (!url)
46
+ return null;
47
+ try {
48
+ const resp = await fetch(url);
49
+ if (!resp.ok)
50
+ return null;
51
+ const text = await resp.text();
52
+ const addrs = clearNewLine(text);
53
+ // Only changed values go through the change callback (onNameServerAddressChange -> updateNameServerAddressList); unchanged answers stay silent.
54
+ if (addrs != null && addrs !== '' && addrs !== this.lastAddrs) {
55
+ const prev = this.lastAddrs;
56
+ this.lastAddrs = addrs;
57
+ if (this.changeCallBack != null) {
58
+ try {
59
+ this.changeCallBack(addrs);
60
+ }
61
+ catch (e) { /* never break polling */ }
62
+ }
63
+ }
64
+ return addrs;
65
+ }
66
+ catch (e) {
67
+ return null;
68
+ }
69
+ }
70
+ // Best-effort: fetch and return the namesrv address string (null on any failure).
71
+ async fetchAndApply(subgroup = 'nsaddr') {
72
+ return this.fetchNsAddr(subgroup);
73
+ }
74
+ }
75
+ export default { DefaultTopAddressing, clearNewLine };
@@ -0,0 +1,61 @@
1
+ export declare const TraceGroupNamePrefix = "_INNER_TRACE_PRODUCER";
2
+ export declare const TraceContentSplitor = "\u0001";
3
+ export declare const TraceFieldSplitor = "\u0002";
4
+ export declare const TraceInstanceName = "PID_CLIENT_INNER_TRACE_PRODUCER";
5
+ export declare const TraceTopicPrefix = "rmq_sys_TRACE_DATA_";
6
+ export declare const AccessChannelLocal = "LOCAL";
7
+ export declare const AccessChannelCloud = "CLOUD";
8
+ export declare const DefaultTraceRegionId = "DefaultRegion";
9
+ export declare const TraceType: {
10
+ readonly PUB: "Pub";
11
+ readonly RECALL: "Recall";
12
+ readonly SUB_BEFORE: "SubBefore";
13
+ readonly SUB_AFTER: "SubAfter";
14
+ readonly END_TRANSACTION: "EndTransaction";
15
+ };
16
+ export type TraceType = string;
17
+ export declare const TraceMsgType: {
18
+ readonly NORMAL: 0;
19
+ readonly ORDER: 1;
20
+ readonly TRANSACTION: 2;
21
+ readonly DELAY: 3;
22
+ readonly BATCH: 4;
23
+ readonly REPLY: 5;
24
+ };
25
+ export declare class TraceBean {
26
+ topic: string;
27
+ msgId: string;
28
+ offsetMsgId: string;
29
+ tags: string;
30
+ keys: string;
31
+ storeHost: string;
32
+ clientHost: string;
33
+ storeTime: number;
34
+ retryTimes: number;
35
+ bodyLength: number;
36
+ msgType: number;
37
+ transactionState: string;
38
+ transactionId: string;
39
+ fromTransactionCheck: boolean;
40
+ }
41
+ export declare class TraceContext {
42
+ traceType: TraceType;
43
+ timeStamp: number;
44
+ regionId: string;
45
+ regionName: string;
46
+ groupName: string;
47
+ costTime: number;
48
+ isSuccess: boolean;
49
+ requestId: string;
50
+ contextCode: number;
51
+ accessChannel: string | null;
52
+ traceBeans: TraceBean[];
53
+ }
54
+ export declare class TraceTransferBean {
55
+ transData: string;
56
+ transKey: Set<string>;
57
+ }
58
+ export declare function splitTrimmingTrailingEmpty(text: string, sep: string): string[];
59
+ export declare function EncodeTraceContext(ctx: TraceContext | null): TraceTransferBean | null;
60
+ export declare function DecodeTraceDataString(traceData: string): TraceContext[];
61
+ export declare function traceBeanFromMessageExt(msg: any, offsetBasedId: boolean): TraceBean;