rocketmq-client-nodejs 1.0.8 → 1.1.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.md +61 -0
- package/dist/client/BaseClient.d.ts +44 -1
- package/dist/client/BaseClient.js +353 -85
- package/dist/client/Logger.js +9 -6
- package/dist/client/RpcClient.js +42 -134
- package/dist/client/RpcClientManager.d.ts +22 -17
- package/dist/client/RpcClientManager.js +61 -56
- package/dist/client/TelemetrySession.js +107 -17
- package/dist/consumer/ConsumeService.d.ts +2 -1
- package/dist/consumer/ConsumeService.js +12 -6
- package/dist/consumer/ConsumeTask.d.ts +6 -1
- package/dist/consumer/ConsumeTask.js +36 -5
- package/dist/consumer/Consumer.d.ts +13 -5
- package/dist/consumer/Consumer.js +94 -33
- package/dist/consumer/FifoConsumeService.d.ts +3 -1
- package/dist/consumer/FifoConsumeService.js +4 -4
- package/dist/consumer/LiteConsumerSupport.d.ts +25 -0
- package/dist/consumer/LiteConsumerSupport.js +47 -0
- package/dist/consumer/LiteFifoConsumeService.d.ts +3 -1
- package/dist/consumer/LiteFifoConsumeService.js +4 -4
- package/dist/consumer/LitePushConsumerImpl.d.ts +15 -4
- package/dist/consumer/LitePushConsumerImpl.js +26 -30
- package/dist/consumer/LiteSimpleConsumer.d.ts +177 -0
- package/dist/consumer/LiteSimpleConsumer.js +126 -0
- package/dist/consumer/LiteSimpleConsumerImpl.d.ts +133 -0
- package/dist/consumer/LiteSimpleConsumerImpl.js +179 -0
- package/dist/consumer/LiteStandardConsumeService.d.ts +3 -1
- package/dist/consumer/LiteStandardConsumeService.js +4 -4
- package/dist/consumer/LiteSubscriptionManager.d.ts +27 -6
- package/dist/consumer/LiteSubscriptionManager.js +36 -27
- package/dist/consumer/OffsetOption.d.ts +1 -0
- package/dist/consumer/OffsetOption.js +10 -4
- package/dist/consumer/ProcessQueue.d.ts +17 -1
- package/dist/consumer/ProcessQueue.js +134 -91
- package/dist/consumer/PushConsumer.d.ts +17 -0
- package/dist/consumer/PushConsumer.js +117 -26
- package/dist/consumer/PushConsumerGaugeObserver.d.ts +33 -0
- package/dist/consumer/PushConsumerGaugeObserver.js +60 -0
- package/dist/consumer/PushSubscriptionSettings.d.ts +8 -1
- package/dist/consumer/PushSubscriptionSettings.js +35 -8
- package/dist/consumer/SimpleConsumer.d.ts +5 -0
- package/dist/consumer/SimpleConsumer.js +33 -20
- package/dist/consumer/SimpleSubscriptionSettings.js +3 -3
- package/dist/consumer/StandardConsumeService.d.ts +3 -1
- package/dist/consumer/StandardConsumeService.js +17 -8
- package/dist/consumer/SubscriptionLoadBalancer.js +3 -3
- package/dist/consumer/index.d.ts +1 -0
- package/dist/consumer/index.js +2 -1
- package/dist/exception/InternalErrorException.d.ts +1 -0
- package/dist/exception/InternalErrorException.js +3 -2
- package/dist/exception/PayloadEmptyException.d.ts +20 -0
- package/dist/exception/PayloadEmptyException.js +28 -0
- package/dist/exception/StatusChecker.js +11 -4
- package/dist/exception/index.d.ts +1 -0
- package/dist/exception/index.js +2 -1
- package/dist/exception/receiveStatus.d.ts +18 -0
- package/dist/exception/receiveStatus.js +28 -0
- package/dist/hook/Attribute.d.ts +26 -0
- package/dist/hook/Attribute.js +37 -0
- package/dist/hook/AttributeKey.d.ts +32 -0
- package/dist/hook/AttributeKey.js +43 -0
- package/dist/hook/CompositedMessageInterceptor.d.ts +32 -0
- package/dist/hook/CompositedMessageInterceptor.js +87 -0
- package/dist/hook/InflightRequestCountInterceptor.d.ts +28 -0
- package/dist/hook/InflightRequestCountInterceptor.js +44 -0
- package/dist/hook/MessageHookPoints.d.ts +54 -0
- package/dist/hook/MessageHookPoints.js +59 -0
- package/dist/hook/MessageHookPointsStatus.d.ts +24 -0
- package/dist/hook/MessageHookPointsStatus.js +29 -0
- package/dist/hook/MessageInterceptor.d.ts +34 -0
- package/dist/hook/MessageInterceptor.js +19 -0
- package/dist/hook/MessageInterceptorContext.d.ts +31 -0
- package/dist/hook/MessageInterceptorContext.js +19 -0
- package/dist/hook/MessageInterceptorContextImpl.d.ts +40 -0
- package/dist/hook/MessageInterceptorContextImpl.js +71 -0
- package/dist/hook/MessageMeterInterceptor.d.ts +39 -0
- package/dist/hook/MessageMeterInterceptor.js +149 -0
- package/dist/hook/index.d.ts +26 -0
- package/dist/hook/index.js +43 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/dist/message/Message.js +26 -4
- package/dist/message/MessageView.js +15 -5
- package/dist/message/PublishingMessage.js +4 -4
- package/dist/metrics/ClientMeter.d.ts +42 -0
- package/dist/metrics/ClientMeter.js +75 -0
- package/dist/metrics/ClientMeterManager.d.ts +46 -0
- package/dist/metrics/ClientMeterManager.js +203 -0
- package/dist/metrics/EmptyGaugeObserver.d.ts +28 -0
- package/dist/metrics/EmptyGaugeObserver.js +34 -0
- package/dist/metrics/GaugeEnum.d.ts +32 -0
- package/dist/metrics/GaugeEnum.js +37 -0
- package/dist/metrics/GaugeObserver.d.ts +29 -0
- package/dist/metrics/GaugeObserver.js +19 -0
- package/dist/metrics/HistogramEnum.d.ts +54 -0
- package/dist/metrics/HistogramEnum.js +71 -0
- package/dist/metrics/InvocationStatus.d.ts +26 -0
- package/dist/metrics/InvocationStatus.js +33 -0
- package/dist/metrics/Metric.d.ts +30 -0
- package/dist/metrics/Metric.js +44 -0
- package/dist/metrics/MetricLabels.d.ts +27 -0
- package/dist/metrics/MetricLabels.js +34 -0
- package/dist/metrics/index.d.ts +25 -0
- package/dist/metrics/index.js +42 -0
- package/dist/producer/Producer.d.ts +8 -2
- package/dist/producer/Producer.js +83 -34
- package/dist/producer/PublishingLoadBalancer.js +11 -5
- package/dist/producer/PublishingSettings.js +1 -3
- package/dist/producer/SendReceipt.js +3 -2
- package/dist/producer/Transaction.d.ts +2 -1
- package/dist/producer/Transaction.js +9 -8
- package/dist/producer/index.d.ts +1 -0
- package/dist/producer/index.js +2 -2
- package/dist/retry/CustomizedBackoffRetryPolicy.d.ts +37 -0
- package/dist/retry/CustomizedBackoffRetryPolicy.js +72 -0
- package/dist/retry/ExponentialBackoffRetryPolicy.js +10 -6
- package/dist/retry/RetryPolicy.d.ts +1 -1
- package/dist/retry/index.d.ts +1 -0
- package/dist/retry/index.js +2 -1
- package/dist/route/Endpoints.d.ts +6 -0
- package/dist/route/Endpoints.js +69 -9
- package/dist/route/IpNameResolver.d.ts +28 -0
- package/dist/route/IpNameResolver.js +104 -0
- package/dist/route/MessageQueue.js +7 -2
- package/dist/route/TopicRouteData.d.ts +5 -0
- package/dist/route/TopicRouteData.js +22 -1
- package/dist/util/Semaphore.d.ts +47 -0
- package/dist/util/Semaphore.js +82 -0
- package/dist/util/index.d.ts +1 -1
- package/dist/util/index.js +9 -6
- package/dist/util/rpcContext.d.ts +20 -0
- package/dist/util/rpcContext.js +35 -0
- package/package.json +11 -4
- package/src/client/BaseClient.ts +392 -91
- package/src/client/Logger.ts +9 -5
- package/src/client/RpcClient.ts +62 -133
- package/src/client/RpcClientManager.ts +103 -60
- package/src/client/TelemetrySession.ts +112 -17
- package/src/consumer/ConsumeService.ts +16 -5
- package/src/consumer/ConsumeTask.ts +43 -3
- package/src/consumer/Consumer.ts +116 -35
- package/src/consumer/FifoConsumeService.ts +5 -3
- package/src/consumer/LiteConsumerSupport.ts +49 -0
- package/src/consumer/LiteFifoConsumeService.ts +5 -3
- package/src/consumer/LitePushConsumerImpl.ts +34 -23
- package/src/consumer/LiteSimpleConsumer.ts +251 -0
- package/src/consumer/LiteSimpleConsumerImpl.ts +214 -0
- package/src/consumer/LiteStandardConsumeService.ts +5 -3
- package/src/consumer/LiteSubscriptionManager.ts +66 -41
- package/src/consumer/OffsetOption.ts +10 -3
- package/src/consumer/ProcessQueue.ts +165 -107
- package/src/consumer/PushConsumer.ts +133 -24
- package/src/consumer/PushConsumerGaugeObserver.ts +60 -0
- package/src/consumer/PushSubscriptionSettings.ts +40 -9
- package/src/consumer/SimpleConsumer.ts +39 -23
- package/src/consumer/SimpleSubscriptionSettings.ts +2 -2
- package/src/consumer/StandardConsumeService.ts +18 -7
- package/src/consumer/SubscriptionLoadBalancer.ts +2 -2
- package/src/consumer/index.ts +1 -0
- package/src/exception/InternalErrorException.ts +3 -1
- package/src/exception/PayloadEmptyException.ts +25 -0
- package/src/exception/StatusChecker.ts +10 -2
- package/src/exception/index.ts +1 -0
- package/src/exception/receiveStatus.ts +25 -0
- package/src/hook/Attribute.ts +36 -0
- package/src/hook/AttributeKey.ts +42 -0
- package/src/hook/CompositedMessageInterceptor.ts +96 -0
- package/src/hook/InflightRequestCountInterceptor.ts +46 -0
- package/src/hook/MessageHookPoints.ts +55 -0
- package/src/hook/MessageHookPointsStatus.ts +25 -0
- package/src/hook/MessageInterceptor.ts +35 -0
- package/src/hook/MessageInterceptorContext.ts +33 -0
- package/src/hook/MessageInterceptorContextImpl.ts +83 -0
- package/src/hook/MessageMeterInterceptor.ts +162 -0
- package/src/hook/index.ts +27 -0
- package/src/index.ts +1 -0
- package/src/message/Message.ts +25 -3
- package/src/message/MessageView.ts +13 -4
- package/src/message/PublishingMessage.ts +3 -3
- package/src/metrics/ClientMeter.ts +81 -0
- package/src/metrics/ClientMeterManager.ts +227 -0
- package/src/metrics/EmptyGaugeObserver.ts +36 -0
- package/src/metrics/GaugeEnum.ts +33 -0
- package/src/metrics/GaugeObserver.ts +32 -0
- package/src/metrics/HistogramEnum.ts +69 -0
- package/src/metrics/InvocationStatus.ts +28 -0
- package/src/metrics/Metric.ts +42 -0
- package/src/metrics/MetricLabels.ts +31 -0
- package/src/metrics/index.ts +26 -0
- package/src/producer/Producer.ts +94 -38
- package/src/producer/PublishingLoadBalancer.ts +10 -4
- package/src/producer/PublishingSettings.ts +0 -2
- package/src/producer/SendReceipt.ts +2 -1
- package/src/producer/Transaction.ts +12 -11
- package/src/producer/index.ts +1 -1
- package/src/retry/CustomizedBackoffRetryPolicy.ts +81 -0
- package/src/retry/ExponentialBackoffRetryPolicy.ts +11 -6
- package/src/retry/RetryPolicy.ts +1 -1
- package/src/retry/index.ts +1 -0
- package/src/route/Endpoints.ts +65 -8
- package/src/route/IpNameResolver.ts +119 -0
- package/src/route/MessageQueue.ts +6 -1
- package/src/route/TopicRouteData.ts +22 -1
- package/src/util/Semaphore.ts +82 -0
- package/src/util/index.ts +8 -5
- package/src/util/rpcContext.ts +34 -0
|
@@ -21,15 +21,38 @@ import {
|
|
|
21
21
|
SyncLiteSubscriptionRequest,
|
|
22
22
|
SyncLiteSubscriptionResponse,
|
|
23
23
|
} from '../../proto/apache/rocketmq/v2/service_pb';
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
24
|
+
import { Endpoints } from '../route';
|
|
25
|
+
import { ILogger } from '../client/Logger';
|
|
26
|
+
import { RpcClientManager } from '../client/RpcClientManager';
|
|
27
|
+
import { ClientException, LiteSubscriptionQuotaExceededException, StatusChecker } from '../exception';
|
|
28
|
+
import { Resource } from '../route/Resource';
|
|
29
|
+
import { getRequestId } from '../util/rpcContext';
|
|
27
30
|
import { OffsetOption } from './OffsetOption';
|
|
28
31
|
|
|
29
32
|
const SYNC_LITE_SUBSCRIPTION_INTERVAL = 30000; // 30 seconds
|
|
30
33
|
|
|
31
34
|
/**
|
|
32
|
-
*
|
|
35
|
+
* Minimal host contract required by LiteSubscriptionManager.
|
|
36
|
+
*
|
|
37
|
+
* Implemented by LitePushConsumerImpl and LiteSimpleConsumerImpl so the same
|
|
38
|
+
* manager can keep lite subscriptions in sync for both consumer flavors.
|
|
39
|
+
*/
|
|
40
|
+
export interface LiteSubscriptionHost {
|
|
41
|
+
clientId: string;
|
|
42
|
+
isRunning(): boolean;
|
|
43
|
+
getLogger(): ILogger;
|
|
44
|
+
getRpcClientManager(): RpcClientManager;
|
|
45
|
+
getRequestTimeout(): number;
|
|
46
|
+
/**
|
|
47
|
+
* Endpoints the lite subscription should be synced to. Lite subscriptions
|
|
48
|
+
* must reach every route endpoint, not only the endpoint the client was
|
|
49
|
+
* configured with.
|
|
50
|
+
*/
|
|
51
|
+
getSyncEndpoints(): Endpoints[];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Manages lite topic subscriptions for lite consumers.
|
|
33
56
|
*
|
|
34
57
|
* <p>LiteSubscriptionManager handles:
|
|
35
58
|
* - Maintaining the set of subscribed lite topics
|
|
@@ -38,7 +61,7 @@ const SYNC_LITE_SUBSCRIPTION_INTERVAL = 30000; // 30 seconds
|
|
|
38
61
|
* - Handling unsubscribe commands from server</p>
|
|
39
62
|
*/
|
|
40
63
|
export class LiteSubscriptionManager {
|
|
41
|
-
private readonly
|
|
64
|
+
private readonly host: LiteSubscriptionHost;
|
|
42
65
|
private readonly bindTopic: Resource;
|
|
43
66
|
private readonly group: Resource;
|
|
44
67
|
private readonly liteTopicSet = new Set<string>();
|
|
@@ -47,11 +70,11 @@ export class LiteSubscriptionManager {
|
|
|
47
70
|
private syncTimer?: NodeJS.Timeout;
|
|
48
71
|
|
|
49
72
|
constructor(
|
|
50
|
-
|
|
73
|
+
host: LiteSubscriptionHost,
|
|
51
74
|
bindTopic: Resource,
|
|
52
75
|
group: Resource,
|
|
53
76
|
) {
|
|
54
|
-
this.
|
|
77
|
+
this.host = host;
|
|
55
78
|
this.bindTopic = bindTopic;
|
|
56
79
|
this.group = group;
|
|
57
80
|
this.liteSubscriptionQuota = 100; // Default quota
|
|
@@ -62,6 +85,9 @@ export class LiteSubscriptionManager {
|
|
|
62
85
|
* Start periodic sync of lite subscriptions.
|
|
63
86
|
*/
|
|
64
87
|
public startUp() {
|
|
88
|
+
if (this.syncTimer) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
65
91
|
// syncAll after startup for subscribeLite("*")
|
|
66
92
|
this.syncAllLiteSubscription();
|
|
67
93
|
this.syncTimer = setInterval(
|
|
@@ -129,8 +155,8 @@ export class LiteSubscriptionManager {
|
|
|
129
155
|
offsetOption?: OffsetOption | null,
|
|
130
156
|
): Promise<void> {
|
|
131
157
|
// Check if consumer is running
|
|
132
|
-
if (!this.
|
|
133
|
-
throw new
|
|
158
|
+
if (!this.host.isRunning()) {
|
|
159
|
+
throw new Error('Consumer is not running');
|
|
134
160
|
}
|
|
135
161
|
|
|
136
162
|
// Already subscribed
|
|
@@ -152,15 +178,15 @@ export class LiteSubscriptionManager {
|
|
|
152
178
|
);
|
|
153
179
|
|
|
154
180
|
this.liteTopicSet.add(liteTopic);
|
|
155
|
-
this.
|
|
181
|
+
this.host.getLogger().info(
|
|
156
182
|
'SubscribeLite %s, topic=%s, group=%s, clientId=%s',
|
|
157
183
|
liteTopic,
|
|
158
184
|
this.getBindTopicName(),
|
|
159
185
|
this.getConsumerGroupName(),
|
|
160
|
-
this.
|
|
186
|
+
this.host.clientId,
|
|
161
187
|
);
|
|
162
188
|
} catch (error) {
|
|
163
|
-
this.
|
|
189
|
+
this.host.getLogger().error(
|
|
164
190
|
'Failed to subscribeLite %s, error=%s',
|
|
165
191
|
liteTopic,
|
|
166
192
|
error,
|
|
@@ -174,8 +200,8 @@ export class LiteSubscriptionManager {
|
|
|
174
200
|
*/
|
|
175
201
|
public async unsubscribeLite(liteTopic: string): Promise<void> {
|
|
176
202
|
// Check if consumer is running
|
|
177
|
-
if (!this.
|
|
178
|
-
throw new
|
|
203
|
+
if (!this.host.isRunning()) {
|
|
204
|
+
throw new Error('Consumer is not running');
|
|
179
205
|
}
|
|
180
206
|
|
|
181
207
|
// Not subscribed
|
|
@@ -191,15 +217,15 @@ export class LiteSubscriptionManager {
|
|
|
191
217
|
);
|
|
192
218
|
|
|
193
219
|
this.liteTopicSet.delete(liteTopic);
|
|
194
|
-
this.
|
|
220
|
+
this.host.getLogger().info(
|
|
195
221
|
'UnsubscribeLite %s, topic=%s, group=%s, clientId=%s',
|
|
196
222
|
liteTopic,
|
|
197
223
|
this.getBindTopicName(),
|
|
198
224
|
this.getConsumerGroupName(),
|
|
199
|
-
this.
|
|
225
|
+
this.host.clientId,
|
|
200
226
|
);
|
|
201
227
|
} catch (error) {
|
|
202
|
-
this.
|
|
228
|
+
this.host.getLogger().error(
|
|
203
229
|
'Failed to unsubscribeLite %s, error=%s',
|
|
204
230
|
liteTopic,
|
|
205
231
|
error,
|
|
@@ -220,23 +246,23 @@ export class LiteSubscriptionManager {
|
|
|
220
246
|
null,
|
|
221
247
|
);
|
|
222
248
|
} catch (error) {
|
|
223
|
-
this.
|
|
249
|
+
this.host.getLogger().error(
|
|
224
250
|
'Schedule syncAllLiteSubscription error, clientId=%s, error=%s',
|
|
225
|
-
this.
|
|
251
|
+
this.host.clientId,
|
|
226
252
|
error,
|
|
227
253
|
);
|
|
228
254
|
}
|
|
229
255
|
}
|
|
230
256
|
|
|
231
257
|
/**
|
|
232
|
-
* Sync lite subscription with
|
|
258
|
+
* Sync lite subscription with every route endpoint.
|
|
233
259
|
*/
|
|
234
260
|
private async syncLiteSubscription(
|
|
235
261
|
action: LiteSubscriptionAction,
|
|
236
262
|
liteTopics: string[],
|
|
237
263
|
offsetOption: OffsetOption | null,
|
|
238
264
|
): Promise<void> {
|
|
239
|
-
const logger = this.
|
|
265
|
+
const logger = this.host.getLogger();
|
|
240
266
|
if (logger.debug) {
|
|
241
267
|
logger.debug(
|
|
242
268
|
'SyncLiteSubscription: action=%s, liteTopics=[%s], offsetOption=%s',
|
|
@@ -258,29 +284,27 @@ export class LiteSubscriptionManager {
|
|
|
258
284
|
request.setOffsetOption(offsetOption.toProtobuf());
|
|
259
285
|
}
|
|
260
286
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
request,
|
|
266
|
-
this.consumerImpl.getRequestTimeout(),
|
|
267
|
-
);
|
|
287
|
+
const endpointsList = this.host.getSyncEndpoints();
|
|
288
|
+
if (endpointsList.length === 0) {
|
|
289
|
+
throw new ClientException(500, 'No endpoints available to sync lite subscription');
|
|
290
|
+
}
|
|
268
291
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
if
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
)
|
|
276
|
-
|
|
292
|
+
try {
|
|
293
|
+
// The lite subscription must reach every route endpoint; the sync fails
|
|
294
|
+
// if any endpoint rejects it.
|
|
295
|
+
await Promise.all(endpointsList.map(async endpoints => {
|
|
296
|
+
const response: SyncLiteSubscriptionResponse = await this.host.getRpcClientManager()
|
|
297
|
+
.syncLiteSubscription(endpoints, request, this.host.getRequestTimeout());
|
|
298
|
+
// Map the status to typed exceptions (e.g. LiteSubscriptionQuotaExceededException), as Java does.
|
|
299
|
+
StatusChecker.check(response.getStatus()?.toObject(), getRequestId(response));
|
|
300
|
+
}));
|
|
277
301
|
|
|
278
302
|
if (logger.info) {
|
|
279
303
|
logger.info(
|
|
280
304
|
'SyncLiteSubscription success: action=%s, liteTopics=[%s], clientId=%s',
|
|
281
305
|
LiteSubscriptionAction[action],
|
|
282
306
|
liteTopics.join(', '),
|
|
283
|
-
this.
|
|
307
|
+
this.host.clientId,
|
|
284
308
|
);
|
|
285
309
|
}
|
|
286
310
|
} catch (error) {
|
|
@@ -289,7 +313,7 @@ export class LiteSubscriptionManager {
|
|
|
289
313
|
'SyncLiteSubscription failed: action=%s, liteTopics=[%s], clientId=%s, error=%s',
|
|
290
314
|
LiteSubscriptionAction[action],
|
|
291
315
|
liteTopics.join(', '),
|
|
292
|
-
this.
|
|
316
|
+
this.host.clientId,
|
|
293
317
|
error,
|
|
294
318
|
);
|
|
295
319
|
}
|
|
@@ -302,7 +326,7 @@ export class LiteSubscriptionManager {
|
|
|
302
326
|
*/
|
|
303
327
|
public onNotifyUnsubscribeLiteCommand(command: NotifyUnsubscribeLiteCommand) {
|
|
304
328
|
const liteTopic = command.getLiteTopic();
|
|
305
|
-
this.
|
|
329
|
+
this.host.getLogger().info(
|
|
306
330
|
'Notify unsubscribe lite: liteTopic=%s, group=%s, bindTopic=%s',
|
|
307
331
|
liteTopic,
|
|
308
332
|
this.getConsumerGroupName(),
|
|
@@ -336,8 +360,9 @@ export class LiteSubscriptionManager {
|
|
|
336
360
|
*/
|
|
337
361
|
private checkLiteSubscriptionQuota(delta: number) {
|
|
338
362
|
if (this.liteTopicSet.size + delta > this.liteSubscriptionQuota) {
|
|
339
|
-
throw new
|
|
340
|
-
|
|
363
|
+
throw new LiteSubscriptionQuotaExceededException(
|
|
364
|
+
Code.LITE_SUBSCRIPTION_QUOTA_EXCEEDED,
|
|
365
|
+
null,
|
|
341
366
|
`Lite subscription quota exceeded ${this.liteSubscriptionQuota}`,
|
|
342
367
|
);
|
|
343
368
|
}
|
|
@@ -63,6 +63,13 @@ export class OffsetOption {
|
|
|
63
63
|
this.value = value;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
private static toBigInt(value: number | bigint, name: string): bigint {
|
|
67
|
+
if (typeof value === 'number' && !Number.isSafeInteger(value)) {
|
|
68
|
+
throw new RangeError(`${name} must be a safe integer when provided as number`);
|
|
69
|
+
}
|
|
70
|
+
return typeof value === 'number' ? BigInt(value) : value;
|
|
71
|
+
}
|
|
72
|
+
|
|
66
73
|
/**
|
|
67
74
|
* Create an OffsetOption from a specific offset.
|
|
68
75
|
*
|
|
@@ -71,7 +78,7 @@ export class OffsetOption {
|
|
|
71
78
|
* @throws Error if offset is negative
|
|
72
79
|
*/
|
|
73
80
|
static ofOffset(offset: number | bigint): OffsetOption {
|
|
74
|
-
const value =
|
|
81
|
+
const value = OffsetOption.toBigInt(offset, 'offset');
|
|
75
82
|
if (value < BigInt(0)) {
|
|
76
83
|
throw new Error('offset must be greater than or equal to 0');
|
|
77
84
|
}
|
|
@@ -86,7 +93,7 @@ export class OffsetOption {
|
|
|
86
93
|
* @throws Error if tailN is negative
|
|
87
94
|
*/
|
|
88
95
|
static ofTailN(tailN: number | bigint): OffsetOption {
|
|
89
|
-
const value =
|
|
96
|
+
const value = OffsetOption.toBigInt(tailN, 'tailN');
|
|
90
97
|
if (value < BigInt(0)) {
|
|
91
98
|
throw new Error('tailN must be greater than or equal to 0');
|
|
92
99
|
}
|
|
@@ -101,7 +108,7 @@ export class OffsetOption {
|
|
|
101
108
|
* @throws Error if timestamp is negative
|
|
102
109
|
*/
|
|
103
110
|
static ofTimestamp(timestamp: number | bigint): OffsetOption {
|
|
104
|
-
const value =
|
|
111
|
+
const value = OffsetOption.toBigInt(timestamp, 'timestamp');
|
|
105
112
|
if (value < BigInt(0)) {
|
|
106
113
|
throw new Error('timestamp must be greater than or equal to 0');
|
|
107
114
|
}
|