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,15 @@
1
+ export declare class PopProcessQueue {
2
+ lastPopTimestamp: number;
3
+ waitAckCounter: number;
4
+ dropped: boolean;
5
+ constructor();
6
+ getLastPopTimestamp(): number;
7
+ setLastPopTimestamp(ts: number): void;
8
+ incFoundMsg(count: number): void;
9
+ ack(): number;
10
+ decFoundMsg(count: number): void;
11
+ waitAckMsgCount(): number;
12
+ isDropped(): boolean;
13
+ setDropped(dropped?: boolean): void;
14
+ isPullExpired(): boolean;
15
+ }
@@ -0,0 +1,51 @@
1
+ // -*- coding: utf-8 -*-
2
+ // PopProcessQueue — queue state under POP consumption.
3
+ //
4
+ // It is deliberately NOT a normal ProcessQueue: POP has neither an offset
5
+ // cursor nor message buffering. The broker hands out a batch of invisible
6
+ // messages; the client must ACK each one or extend the invisibility period, and
7
+ // the client only tracks "how many replies are still owed", and that count is
8
+ // the amount read for flow control.
9
+ //
10
+ // Two traps in this class: `ack()` returns the value BEFORE the decrement;
11
+ // `decFoundMsg()` ADDS instead of subtracts — it is the "this batch is
12
+ // withdrawn, hang the debt back on" path. Both must be preserved as-is, because
13
+ // ConsumeMessagePopConcurrentlyService depends on this sign direction.
14
+ import { currentTimeMillis } from "../common/utilAll.js";
15
+ // Idle cap reused by POP (default 120000ms, overridable via ROCKETMQ_CLIENT_PULL_MAX_IDLE_TIME).
16
+ const POP_PULL_MAX_IDLE_TIME = (() => {
17
+ const raw = process.env.ROCKETMQ_CLIENT_PULL_MAX_IDLE_TIME;
18
+ if (!raw)
19
+ return 120000;
20
+ const v = parseInt(raw, 10);
21
+ return Number.isFinite(v) && v > 0 ? v : 120000;
22
+ })();
23
+ export class PopProcessQueue {
24
+ lastPopTimestamp;
25
+ waitAckCounter = 0;
26
+ dropped = false;
27
+ constructor() {
28
+ this.lastPopTimestamp = currentTimeMillis();
29
+ }
30
+ getLastPopTimestamp() { return this.lastPopTimestamp; }
31
+ setLastPopTimestamp(ts) { this.lastPopTimestamp = ts; }
32
+ // incFoundMsg: the broker just made this many messages invisible and we owe
33
+ // an answer for each.
34
+ incFoundMsg(count) { this.waitAckCounter += count; }
35
+ // ack(): returns the original value BEFORE the decrement (getAndDecrement semantics); the instant metric reads the pre-decrement amount.
36
+ ack() { return this.waitAckCounter--; }
37
+ // decFoundMsg ADDS: this is the "whole batch withdrawn, hang the owed replies
38
+ // back on" path, used when the queue has already been dropped or the messages
39
+ // have left the invisibility window — undeliverable scenarios. The caller
40
+ // passes a negative number to write the debt off: decFoundMsg(-msgs.length).
41
+ decFoundMsg(count) { this.waitAckCounter += count; }
42
+ // The number of messages not yet ACKed.
43
+ waitAckMsgCount() { return this.waitAckCounter; }
44
+ isDropped() { return this.dropped; }
45
+ setDropped(dropped = true) { this.dropped = dropped; }
46
+ // POP rebalance uses this to evict queues whose pop loop has been silent too
47
+ // long (otherwise the broker would keep reviving their batches).
48
+ isPullExpired() {
49
+ return currentTimeMillis() - this.lastPopTimestamp > POP_PULL_MAX_IDLE_TIME;
50
+ }
51
+ }
@@ -0,0 +1,49 @@
1
+ import { MessageExt } from '../common/message.js';
2
+ export declare const PULL_MAX_IDLE_TIME_MS = 120000;
3
+ export declare const LOCK_MAX_LIVE_TIME_MS = 30000;
4
+ export declare class ProcessQueue {
5
+ dropped: boolean;
6
+ locked: boolean;
7
+ lastLockTimestamp: number;
8
+ tryUnlockTimes: number;
9
+ private msgs;
10
+ private order;
11
+ private dispatched;
12
+ private msgAccCnt;
13
+ private queueOffsetMax;
14
+ lastPullTimestamp: number;
15
+ lastConsumeTimestamp: number;
16
+ consumeOrderly: boolean;
17
+ constructor(consumeOrderly?: boolean);
18
+ putMessage(msgs: MessageExt[]): boolean;
19
+ queueOffsetMaxValue(): number;
20
+ msgAccCntValue(): number;
21
+ heldStats(): [number, number, number];
22
+ msgCount(): number;
23
+ pendingCount(): number;
24
+ msgSizeMB(): number;
25
+ maxSpan(): number;
26
+ firstOffset(): number;
27
+ firstMessage(): MessageExt | null;
28
+ contains(offset: number): boolean;
29
+ takeBatch(max: number): MessageExt[];
30
+ completeBatch(batch: MessageExt[]): void;
31
+ requeueBatch(batch: MessageExt[]): void;
32
+ removeMessage(batch: MessageExt[]): number;
33
+ minRemainingExcept(skip: MessageExt[]): number;
34
+ clear(): void;
35
+ private rebuildOrderLocked;
36
+ setDropped(): void;
37
+ isDropped(): boolean;
38
+ setLocked(locked: boolean): void;
39
+ isLocked(): boolean;
40
+ setLastLockTimestamp(ts: number): void;
41
+ lastLockTimestampValue(): number;
42
+ isLockExpired(): boolean;
43
+ incTryUnlockTimes(): void;
44
+ consumingStats(): [number, number, number];
45
+ touchPull(): void;
46
+ lastPullTimestampValue(): number;
47
+ isPullExpired(): boolean;
48
+ bufferedOffsetSpan(): [number, number, number];
49
+ }
@@ -0,0 +1,261 @@
1
+ import { MessageConst } from "../common/messageConst.js";
2
+ export const PULL_MAX_IDLE_TIME_MS = 120_000;
3
+ // A granted lock only shields the queue for this long; the periodic lock sweep
4
+ // re-grants it, so a stale grant must not gate pulling forever.
5
+ export const LOCK_MAX_LIVE_TIME_MS = 30_000;
6
+ // processQueue is the per-queue state.
7
+ export class ProcessQueue {
8
+ dropped = false;
9
+ locked = false;
10
+ lastLockTimestamp = 0; // unix millis of the last LOCK_BATCH_MQ grant
11
+ tryUnlockTimes = 0;
12
+ // msgs holds every pulled-but-unacked message keyed by queueOffset.
13
+ msgs = new Map();
14
+ order = []; // ascending queueOffsets, kept in sync with msgs
15
+ // dispatched marks entries already handed to a listener.
16
+ dispatched = new Set();
17
+ msgAccCnt = 0;
18
+ queueOffsetMax = 0;
19
+ lastPullTimestamp = 0; // unix millis
20
+ lastConsumeTimestamp = 0; // unix millis of the last completion
21
+ consumeOrderly;
22
+ constructor(consumeOrderly = false) {
23
+ this.consumeOrderly = consumeOrderly;
24
+ }
25
+ putMessage(msgs) {
26
+ const wasEmpty = this.msgs.size === 0;
27
+ for (const msg of msgs) {
28
+ const offset = msg.getQueueOffset();
29
+ if (!this.msgs.has(offset)) {
30
+ insertOffset(this.order, offset);
31
+ }
32
+ this.msgs.set(offset, msg);
33
+ if (offset > this.queueOffsetMax)
34
+ this.queueOffsetMax = offset;
35
+ }
36
+ this.msgAccCnt = computeMsgAccCnt(this.msgAccCnt, msgs);
37
+ return wasEmpty && this.msgs.size > 0;
38
+ }
39
+ queueOffsetMaxValue() {
40
+ return this.queueOffsetMax;
41
+ }
42
+ // MsgAccCnt returns the backlog computed by the last PutMessage.
43
+ msgAccCntValue() {
44
+ return this.msgAccCnt;
45
+ }
46
+ // HeldStats is the flow-control triple (count, whole MiB of message BODY, offset
47
+ // span) over EVERYTHING this queue still holds: the undispatched buffer plus the
48
+ // batches that are already in the listener's hands. A dispatched batch has only
49
+ // moved, it has not left the queue — it leaves when it settles (completeBatch /
50
+ // removeMessage) — so a gate that read the buffer alone would let a queue whose
51
+ // listener is wedged keep pulling, which is exactly what the cache thresholds
52
+ // exist to stop.
53
+ //
54
+ // The byte sum is the BODY the client keeps in memory after decoding, never the
55
+ // wire-side store size, and it is divided by whole MiB: a partially filled MiB
56
+ // costs nothing toward the budget.
57
+ heldStats() {
58
+ let count = 0;
59
+ let bytes = 0;
60
+ let minOffset = 0;
61
+ let maxOffset = 0;
62
+ let first = true;
63
+ for (const offset of this.order) {
64
+ const msg = this.msgs.get(offset);
65
+ if (!msg)
66
+ continue;
67
+ count++;
68
+ const body = msg.getBody();
69
+ bytes += body ? body.length : 0;
70
+ if (first || offset < minOffset)
71
+ minOffset = offset;
72
+ if (first || offset > maxOffset)
73
+ maxOffset = offset;
74
+ first = false;
75
+ }
76
+ const span = count > 0 ? maxOffset - minOffset : 0;
77
+ return [count, Math.floor(bytes / (1024 * 1024)), span];
78
+ }
79
+ msgCount() {
80
+ return this.msgs.size;
81
+ }
82
+ // PendingCount is the number of pulled-and-not-yet-dispatched messages, i.e.
83
+ // the retry buffer. It is NOT what flow control reads: a batch handed to a
84
+ // listener has only moved, it has not left the queue, so the gates judge
85
+ // heldStats() — the whole held set, listener-held batches included.
86
+ pendingCount() {
87
+ return this.msgs.size - this.dispatched.size;
88
+ }
89
+ msgSizeMB() {
90
+ let total = 0;
91
+ for (const msg of this.msgs.values()) {
92
+ const body = msg.getBody();
93
+ total += body ? body.length : 0;
94
+ }
95
+ return total / (1024.0 * 1024.0);
96
+ }
97
+ maxSpan() {
98
+ if (this.order.length === 0)
99
+ return 0;
100
+ return this.order[this.order.length - 1] - this.order[0];
101
+ }
102
+ // FirstOffset is the smallest buffered offset (-1 when empty).
103
+ firstOffset() {
104
+ return this.order.length > 0 ? this.order[0] : -1;
105
+ }
106
+ // FirstMessage is the smallest buffered message (cleanExpiredMsg's "head
107
+ // only" rule).
108
+ firstMessage() {
109
+ if (this.order.length === 0)
110
+ return null;
111
+ return this.msgs.get(this.order[0]) || null;
112
+ }
113
+ contains(offset) {
114
+ return this.msgs.has(offset);
115
+ }
116
+ // TakeBatch returns up to max buffered messages in offset order and marks
117
+ // them dispatched, so they cannot be handed out twice.
118
+ takeBatch(max) {
119
+ if (max <= 0)
120
+ max = 1;
121
+ const batch = [];
122
+ for (const offset of this.order) {
123
+ if (batch.length >= max)
124
+ break;
125
+ if (this.dispatched.has(offset))
126
+ continue;
127
+ const msg = this.msgs.get(offset);
128
+ if (!msg)
129
+ continue;
130
+ this.dispatched.add(offset);
131
+ batch.push(msg);
132
+ }
133
+ if (batch.length > 0)
134
+ this.lastConsumeTimestamp = Date.now();
135
+ return batch;
136
+ }
137
+ // CompleteBatch drops the batch from the buffer (the ack path).
138
+ completeBatch(batch) {
139
+ for (const msg of batch) {
140
+ this.msgs.delete(msg.getQueueOffset());
141
+ this.dispatched.delete(msg.getQueueOffset());
142
+ }
143
+ this.rebuildOrderLocked();
144
+ }
145
+ // RequeueBatch makes the batch eligible for dispatch again (rollback /
146
+ // suspend / a send-back that failed).
147
+ requeueBatch(batch) {
148
+ for (const msg of batch) {
149
+ this.dispatched.delete(msg.getQueueOffset());
150
+ }
151
+ this.lastConsumeTimestamp = Date.now();
152
+ }
153
+ // RemoveMessage drops the given messages and returns the smallest offset
154
+ // still buffered (-1 when nothing is left). It is cleanExpiredMsg's remover:
155
+ // that caller throws the result away, because the sweep only runs when the
156
+ // entry really is the head. The ACK path must NOT use it — it has to consult
157
+ // the buffer BEFORE mutating it (the removal and the commit write have to
158
+ // stay on opposite sides of the consumer's lock), which is what
159
+ // minRemainingExcept is for.
160
+ removeMessage(batch) {
161
+ for (const msg of batch) {
162
+ this.msgs.delete(msg.getQueueOffset());
163
+ this.dispatched.delete(msg.getQueueOffset());
164
+ }
165
+ this.rebuildOrderLocked();
166
+ return this.order.length > 0 ? this.order[0] : -1;
167
+ }
168
+ minRemainingExcept(skip) {
169
+ const skipSet = new Set();
170
+ for (const msg of skip)
171
+ skipSet.add(msg.getQueueOffset());
172
+ for (const offset of this.order) {
173
+ if (skipSet.has(offset))
174
+ continue;
175
+ return offset;
176
+ }
177
+ return -1;
178
+ }
179
+ clear() {
180
+ this.msgs.clear();
181
+ this.dispatched.clear();
182
+ this.order = [];
183
+ this.queueOffsetMax = 0;
184
+ }
185
+ rebuildOrderLocked() {
186
+ this.order = Array.from(this.msgs.keys());
187
+ this.order.sort((a, b) => a - b);
188
+ }
189
+ setDropped() { this.dropped = true; }
190
+ isDropped() { return this.dropped; }
191
+ // SetLocked records the LOCK_BATCH_MQ outcome for orderly consumption. The
192
+ // grant timestamp is stamped separately by the sweep.
193
+ setLocked(locked) { this.locked = locked; }
194
+ isLocked() { return this.locked; }
195
+ setLastLockTimestamp(ts) { this.lastLockTimestamp = ts; }
196
+ lastLockTimestampValue() { return this.lastLockTimestamp; }
197
+ // A lock grant older than the live time is treated as unlocked at the pull
198
+ // gate; the periodic sweep is what renews it.
199
+ isLockExpired() {
200
+ return Date.now() - this.lastLockTimestamp > LOCK_MAX_LIVE_TIME_MS;
201
+ }
202
+ incTryUnlockTimes() { this.tryUnlockTimes++; }
203
+ // ConsumingStats is [min, max, count] over the batches handed to a listener
204
+ // but not settled yet (the orderly transaction view).
205
+ consumingStats() {
206
+ let min = -1;
207
+ let max = -1;
208
+ let count = 0;
209
+ for (const offset of this.order) {
210
+ if (!this.dispatched.has(offset))
211
+ continue;
212
+ if (min < 0 || offset < min)
213
+ min = offset;
214
+ if (offset > max)
215
+ max = offset;
216
+ count++;
217
+ }
218
+ return [min, max, count];
219
+ }
220
+ // TouchPull stamps "a pull was started", the isPullExpired input.
221
+ touchPull() { this.lastPullTimestamp = Date.now(); }
222
+ lastPullTimestampValue() { return this.lastPullTimestamp; }
223
+ isPullExpired() {
224
+ if (this.lastPullTimestamp === 0)
225
+ return false;
226
+ return Date.now() - this.lastPullTimestamp > PULL_MAX_IDLE_TIME_MS;
227
+ }
228
+ // BufferedOffsetSpan is a tiny helper for logs.
229
+ bufferedOffsetSpan() {
230
+ if (this.order.length === 0)
231
+ return [0, 0, 0];
232
+ return [this.order[0], this.order[this.order.length - 1], this.order.length];
233
+ }
234
+ }
235
+ // ---------------------------------------------------------------- helpers
236
+ function insertOffset(sorted, v) {
237
+ let lo = 0, hi = sorted.length;
238
+ while (lo < hi) {
239
+ const mid = (lo + hi) >> 1;
240
+ if (sorted[mid] < v)
241
+ lo = mid + 1;
242
+ else
243
+ hi = mid;
244
+ }
245
+ sorted.splice(lo, 0, v);
246
+ }
247
+ function computeMsgAccCnt(current, msgs) {
248
+ if (msgs.length === 0)
249
+ return current;
250
+ const last = msgs[msgs.length - 1];
251
+ const raw = last.getProperty(MessageConst.PROPERTY_MAX_OFFSET);
252
+ if (raw != null) {
253
+ const maxOffset = parseInt(String(raw).trim(), 10);
254
+ if (!Number.isNaN(maxOffset)) {
255
+ const acc = maxOffset - last.getQueueOffset();
256
+ if (acc > 0)
257
+ return acc;
258
+ }
259
+ }
260
+ return current;
261
+ }
@@ -0,0 +1,75 @@
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 DEFAULT_TOTAL_HOLD_SIZE: number;
5
+ export declare const DEFAULT_HOLD_SIZE: number;
6
+ export declare const DEFAULT_HOLD_MS = 10;
7
+ export declare class AggregateKey {
8
+ topic: string;
9
+ mq: MessageQueue;
10
+ waitStoreMsgOK: boolean;
11
+ tag: string | null;
12
+ constructor(topic: string, mq: MessageQueue, waitStoreMsgOK: boolean, tag: string | null);
13
+ keyString(): string;
14
+ equals(other: AggregateKey): boolean;
15
+ }
16
+ export declare class AccumulatedSend {
17
+ readonly message: Message;
18
+ readonly mq: MessageQueue;
19
+ readonly promise: Promise<SendResult>;
20
+ private settleResult;
21
+ private settleError;
22
+ constructor(message: Message, mq: MessageQueue);
23
+ complete(result: SendResult): void;
24
+ completeExceptionally(err: Error): void;
25
+ }
26
+ export declare class MessageAccumulation {
27
+ entries: AccumulatedSend[];
28
+ totalSize: number;
29
+ constructor();
30
+ add(entry: AccumulatedSend, size: number): void;
31
+ get messages(): Message[];
32
+ get count(): number;
33
+ get size(): number;
34
+ isEmpty(): boolean;
35
+ clear(): void;
36
+ complete(batchResult: SendResult): void;
37
+ fail(err: Error): void;
38
+ }
39
+ export declare class ProduceAccumulator {
40
+ maxHoldSize: number;
41
+ holdMs: number;
42
+ clientId: string;
43
+ accumulator: Map<string, MessageAccumulation>;
44
+ sender: ((acc: MessageAccumulation) => Promise<void>) | null;
45
+ private timer;
46
+ private stopped;
47
+ constructor(clientId: string, maxHoldSize?: number, holdMs?: number);
48
+ setSender(fn: (acc: MessageAccumulation) => Promise<void>): void;
49
+ setMaxHoldSize(size: number): void;
50
+ setHoldMs(ms: number): void;
51
+ isBatchable(msg: Message): boolean;
52
+ accumulate(msg: Message, mq: MessageQueue): {
53
+ future: AccumulatedSend;
54
+ flushNow: MessageAccumulation | null;
55
+ };
56
+ drain(): MessageAccumulation[];
57
+ size(): number;
58
+ isStopped(): boolean;
59
+ start(): void;
60
+ flushPending(): Promise<void>;
61
+ stop(): void;
62
+ }
63
+ export declare function getOrCreateProduceAccumulator(clientId: string): ProduceAccumulator;
64
+ export declare function splitSendResults(batchResult: SendResult, msgs: Message[]): SendResult[];
65
+ declare const _default: {
66
+ ProduceAccumulator: typeof ProduceAccumulator;
67
+ AggregateKey: typeof AggregateKey;
68
+ MessageAccumulation: typeof MessageAccumulation;
69
+ getOrCreateProduceAccumulator: typeof getOrCreateProduceAccumulator;
70
+ splitSendResults: typeof splitSendResults;
71
+ DEFAULT_TOTAL_HOLD_SIZE: number;
72
+ DEFAULT_HOLD_SIZE: number;
73
+ DEFAULT_HOLD_MS: number;
74
+ };
75
+ export default _default;