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
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
import { ClientDuplexStream } from '@grpc/grpc-js';
|
|
19
19
|
import { TelemetryCommand } from '../../proto/apache/rocketmq/v2/service_pb';
|
|
20
20
|
import { Endpoints } from '../route';
|
|
21
|
+
import { getRequestId, setRequestId } from '../util/rpcContext';
|
|
21
22
|
import type { BaseClient } from './BaseClient';
|
|
22
23
|
import { ILogger } from './Logger';
|
|
23
24
|
|
|
@@ -25,8 +26,14 @@ export class TelemetrySession {
|
|
|
25
26
|
#endpoints: Endpoints;
|
|
26
27
|
#baseClient: BaseClient;
|
|
27
28
|
#logger: ILogger;
|
|
28
|
-
|
|
29
|
+
// Live stream, or undefined while closed (released or awaiting reconnect).
|
|
30
|
+
#stream?: ClientDuplexStream<TelemetryCommand, TelemetryCommand>;
|
|
29
31
|
#isRefreshing = false;
|
|
32
|
+
#released = false;
|
|
33
|
+
#reconnectTimer?: NodeJS.Timeout;
|
|
34
|
+
// Consecutive failed reconnect attempts, driving the exponential backoff
|
|
35
|
+
// delay; reset once the stream is proven alive by inbound data.
|
|
36
|
+
#reconnectAttempts = 0;
|
|
30
37
|
|
|
31
38
|
constructor(baseClient: BaseClient, endpoints: Endpoints, logger: ILogger) {
|
|
32
39
|
this.#endpoints = endpoints;
|
|
@@ -38,11 +45,31 @@ export class TelemetrySession {
|
|
|
38
45
|
}
|
|
39
46
|
|
|
40
47
|
release() {
|
|
48
|
+
if (this.#released) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
this.#released = true;
|
|
52
|
+
if (this.#reconnectTimer) {
|
|
53
|
+
clearTimeout(this.#reconnectTimer);
|
|
54
|
+
this.#reconnectTimer = undefined;
|
|
55
|
+
}
|
|
41
56
|
this.#logger.info('Begin to release telemetry session, endpoints=%s, clientId=%s',
|
|
42
57
|
this.#endpoints, this.#baseClient.clientId);
|
|
58
|
+
this.#closeStream();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
#closeStream() {
|
|
62
|
+
const stream = this.#stream;
|
|
63
|
+
if (!stream) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
this.#stream = undefined;
|
|
43
67
|
try {
|
|
44
|
-
|
|
45
|
-
|
|
68
|
+
stream.removeAllListeners();
|
|
69
|
+
// The remote may still finish the call with a non-OK status after the
|
|
70
|
+
// half-close; an 'error' event without any listener would crash the process.
|
|
71
|
+
stream.on('error', () => undefined);
|
|
72
|
+
stream.end();
|
|
46
73
|
} catch (e) {
|
|
47
74
|
this.#logger.warn('Failed to release telemetry session gracefully, endpoints=%s, clientId=%s, error=%s',
|
|
48
75
|
this.#endpoints, this.#baseClient.clientId, e instanceof Error ? e.message : String(e));
|
|
@@ -50,7 +77,19 @@ export class TelemetrySession {
|
|
|
50
77
|
}
|
|
51
78
|
|
|
52
79
|
write(command: TelemetryCommand) {
|
|
53
|
-
this.#stream
|
|
80
|
+
const stream = this.#stream;
|
|
81
|
+
if (!stream) {
|
|
82
|
+
// Released, or waiting for reconnect: the renewed stream syncs settings itself.
|
|
83
|
+
this.#logger.warn('Telemetry stream is not available, drop the command, endpoints=%s, clientId=%s, released=%s',
|
|
84
|
+
this.#endpoints, this.#baseClient.clientId, this.#released);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
stream.write(command);
|
|
89
|
+
} catch (e) {
|
|
90
|
+
this.#logger.error('Failed to write telemetry command, endpoints=%s, clientId=%s, error=%s',
|
|
91
|
+
this.#endpoints, this.#baseClient.clientId, e instanceof Error ? e.message : String(e));
|
|
92
|
+
}
|
|
54
93
|
}
|
|
55
94
|
|
|
56
95
|
syncSettings() {
|
|
@@ -70,11 +109,18 @@ export class TelemetrySession {
|
|
|
70
109
|
this.#endpoints, this.#baseClient.clientId);
|
|
71
110
|
|
|
72
111
|
try {
|
|
73
|
-
this
|
|
112
|
+
if (this.#reconnectTimer) {
|
|
113
|
+
clearTimeout(this.#reconnectTimer);
|
|
114
|
+
this.#reconnectTimer = undefined;
|
|
115
|
+
}
|
|
116
|
+
this.#closeStream();
|
|
74
117
|
this.#renewStream(false);
|
|
75
118
|
} catch (err) {
|
|
76
119
|
this.#logger.error('Failed to refresh telemetry session, endpoints=%s, clientId=%s, error=%s',
|
|
77
120
|
this.#endpoints, this.#baseClient.clientId, err);
|
|
121
|
+
// The stream is gone and the renewal failed; keep retrying in the
|
|
122
|
+
// background instead of leaving the session permanently dead.
|
|
123
|
+
this.#scheduleRenewStream();
|
|
78
124
|
} finally {
|
|
79
125
|
this.#isRefreshing = false;
|
|
80
126
|
}
|
|
@@ -84,10 +130,11 @@ export class TelemetrySession {
|
|
|
84
130
|
try {
|
|
85
131
|
this.#logger.debug?.('Creating telemetry stream, endpoints=%s, clientId=%s, inited=%s',
|
|
86
132
|
this.#endpoints, this.#baseClient.clientId, inited);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
133
|
+
const stream = this.#baseClient.createTelemetryStream(this.#endpoints);
|
|
134
|
+
stream.on('data', this.#onData.bind(this));
|
|
135
|
+
stream.once('error', this.#onError.bind(this));
|
|
136
|
+
stream.once('end', this.#onEnd.bind(this));
|
|
137
|
+
this.#stream = stream;
|
|
91
138
|
if (!inited) {
|
|
92
139
|
this.#logger.info('Syncing settings to new stream, endpoints=%s, clientId=%s',
|
|
93
140
|
this.#endpoints, this.#baseClient.clientId);
|
|
@@ -101,6 +148,19 @@ export class TelemetrySession {
|
|
|
101
148
|
}
|
|
102
149
|
|
|
103
150
|
#onData(command: TelemetryCommand) {
|
|
151
|
+
// Inbound data proves the stream is alive: reset the reconnect backoff.
|
|
152
|
+
this.#reconnectAttempts = 0;
|
|
153
|
+
try {
|
|
154
|
+
this.#dispatch(command);
|
|
155
|
+
} catch (e) {
|
|
156
|
+
// Mirrors Java ClientSessionImpl#onNext: a failing handler must not
|
|
157
|
+
// escape the stream callback as an uncaughtException.
|
|
158
|
+
this.#logger.error('[Bug] Unexpected exception raised while receiving command from remote, endpoints=%s, clientId=%s, error=%s',
|
|
159
|
+
this.#endpoints, this.#baseClient.clientId, e instanceof Error ? e.message : String(e));
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
#dispatch(command: TelemetryCommand) {
|
|
104
164
|
const endpoints = this.#endpoints;
|
|
105
165
|
const clientId = this.#baseClient.clientId;
|
|
106
166
|
const commandCase = command.getCommandCase();
|
|
@@ -134,31 +194,66 @@ export class TelemetrySession {
|
|
|
134
194
|
this.#baseClient.onReconnectEndpointsCommand(endpoints, command.getReconnectEndpointsCommand()!);
|
|
135
195
|
break;
|
|
136
196
|
}
|
|
197
|
+
case TelemetryCommand.CommandCase.NOTIFY_UNSUBSCRIBE_LITE_COMMAND: {
|
|
198
|
+
this.#logger.info('Receive notify unsubscribe lite command from remote, endpoints=%s, clientId=%s',
|
|
199
|
+
endpoints, clientId);
|
|
200
|
+
this.#baseClient.onNotifyUnsubscribeLiteCommand(endpoints, command.getNotifyUnsubscribeLiteCommand()!);
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
137
203
|
default: {
|
|
138
204
|
const commandObj = command.toObject();
|
|
139
205
|
this.#logger.warn('Receive unrecognized command from remote, endpoints=%s, commandCase=%j, command=%j, clientId=%s',
|
|
140
206
|
endpoints, commandCase, commandObj, clientId);
|
|
141
207
|
// should telemetry session start fail
|
|
208
|
+
if (commandObj.status) setRequestId(commandObj.status, getRequestId(this.#stream));
|
|
142
209
|
this.#baseClient.onUnknownCommand(endpoints, commandObj.status!);
|
|
143
210
|
}
|
|
144
211
|
}
|
|
145
212
|
}
|
|
146
213
|
|
|
214
|
+
/**
|
|
215
|
+
* Schedule a telemetry stream renewal with exponential backoff (1s, 2s,
|
|
216
|
+
* 4s, ... capped at 60s). The timer is tracked so that it can be cancelled
|
|
217
|
+
* on release(), and a pending timer doubles as a guard to prevent
|
|
218
|
+
* error/end events from scheduling duplicate reconnects.
|
|
219
|
+
*/
|
|
220
|
+
#scheduleRenewStream() {
|
|
221
|
+
if (this.#released || this.#reconnectTimer) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const delay = Math.min(1000 * 2 ** this.#reconnectAttempts, 60000);
|
|
225
|
+
this.#reconnectAttempts++;
|
|
226
|
+
this.#reconnectTimer = setTimeout(() => {
|
|
227
|
+
this.#reconnectTimer = undefined;
|
|
228
|
+
if (this.#released) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
try {
|
|
232
|
+
this.#renewStream(false);
|
|
233
|
+
} catch (err) {
|
|
234
|
+
// Never rethrow here: an exception escaping a timer callback becomes
|
|
235
|
+
// an uncaughtException, and without this catch a single transient
|
|
236
|
+
// stream-creation failure would permanently end the reconnect loop
|
|
237
|
+
// and the session would never be able to re-register settings.
|
|
238
|
+
this.#logger.error('Failed to renew telemetry stream, will retry, endpoints=%s, clientId=%s, attempt=%d, error=%s',
|
|
239
|
+
this.#endpoints, this.#baseClient.clientId, this.#reconnectAttempts,
|
|
240
|
+
err instanceof Error ? err.message : String(err));
|
|
241
|
+
this.#scheduleRenewStream();
|
|
242
|
+
}
|
|
243
|
+
}, delay);
|
|
244
|
+
}
|
|
245
|
+
|
|
147
246
|
#onError(err: Error) {
|
|
148
247
|
this.#logger.error('Exception raised from stream response observer, endpoints=%s, clientId=%s, error=%s',
|
|
149
248
|
this.#endpoints, this.#baseClient.clientId, err);
|
|
150
|
-
this
|
|
151
|
-
|
|
152
|
-
this.#renewStream(false);
|
|
153
|
-
}, 1000);
|
|
249
|
+
this.#closeStream();
|
|
250
|
+
this.#scheduleRenewStream();
|
|
154
251
|
}
|
|
155
252
|
|
|
156
253
|
#onEnd() {
|
|
157
254
|
this.#logger.info('Receive completion for stream response observer, endpoints=%s, clientId=%s',
|
|
158
255
|
this.#endpoints, this.#baseClient.clientId);
|
|
159
|
-
this
|
|
160
|
-
|
|
161
|
-
this.#renewStream(false);
|
|
162
|
-
}, 1000);
|
|
256
|
+
this.#closeStream();
|
|
257
|
+
this.#scheduleRenewStream();
|
|
163
258
|
}
|
|
164
259
|
}
|
|
@@ -15,20 +15,28 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
import { MessageView } from '../message';
|
|
18
|
+
import { MessageInterceptor } from '../hook';
|
|
18
19
|
import { ConsumeResult } from './ConsumeResult';
|
|
19
20
|
import { ConsumeTask } from './ConsumeTask';
|
|
20
21
|
import { MessageListener } from './MessageListener';
|
|
21
22
|
import type { ProcessQueue } from './ProcessQueue';
|
|
22
23
|
|
|
24
|
+
type ResolveConsumeResult = (result: ConsumeResult) => void;
|
|
25
|
+
|
|
23
26
|
export abstract class ConsumeService {
|
|
24
27
|
protected readonly clientId: string;
|
|
25
28
|
readonly #messageListener: MessageListener;
|
|
29
|
+
readonly #messageInterceptor?: MessageInterceptor;
|
|
30
|
+
readonly #consumerGroup?: string;
|
|
26
31
|
#aborted = false;
|
|
27
|
-
#pendingTimers
|
|
32
|
+
#pendingTimers = new Map<NodeJS.Timeout, ResolveConsumeResult>();
|
|
28
33
|
|
|
29
|
-
constructor(clientId: string, messageListener: MessageListener
|
|
34
|
+
constructor(clientId: string, messageListener: MessageListener,
|
|
35
|
+
messageInterceptor?: MessageInterceptor, consumerGroup?: string) {
|
|
30
36
|
this.clientId = clientId;
|
|
31
37
|
this.#messageListener = messageListener;
|
|
38
|
+
this.#messageInterceptor = messageInterceptor;
|
|
39
|
+
this.#consumerGroup = consumerGroup;
|
|
32
40
|
}
|
|
33
41
|
|
|
34
42
|
abstract consume(pq: ProcessQueue, messageViews: MessageView[]): void;
|
|
@@ -37,7 +45,8 @@ export abstract class ConsumeService {
|
|
|
37
45
|
if (this.#aborted) {
|
|
38
46
|
return ConsumeResult.FAILURE;
|
|
39
47
|
}
|
|
40
|
-
const task = new ConsumeTask(this.clientId, this.#messageListener, messageView
|
|
48
|
+
const task = new ConsumeTask(this.clientId, this.#messageListener, messageView,
|
|
49
|
+
this.#messageInterceptor, this.#consumerGroup);
|
|
41
50
|
if (delay <= 0) {
|
|
42
51
|
return this.#executeTask(task);
|
|
43
52
|
}
|
|
@@ -51,7 +60,7 @@ export abstract class ConsumeService {
|
|
|
51
60
|
const result = await this.#executeTask(task);
|
|
52
61
|
resolve(result);
|
|
53
62
|
}, delay);
|
|
54
|
-
this.#pendingTimers.
|
|
63
|
+
this.#pendingTimers.set(timer, resolve);
|
|
55
64
|
});
|
|
56
65
|
}
|
|
57
66
|
|
|
@@ -64,8 +73,10 @@ export abstract class ConsumeService {
|
|
|
64
73
|
}
|
|
65
74
|
abort() {
|
|
66
75
|
this.#aborted = true;
|
|
67
|
-
for (const timer of this.#pendingTimers) {
|
|
76
|
+
for (const [ timer, resolve ] of this.#pendingTimers) {
|
|
68
77
|
clearTimeout(timer);
|
|
78
|
+
// Settle the waiter as well, otherwise the caller would hang forever.
|
|
79
|
+
resolve(ConsumeResult.FAILURE);
|
|
69
80
|
}
|
|
70
81
|
this.#pendingTimers.clear();
|
|
71
82
|
}
|
|
@@ -16,24 +16,64 @@
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
import { MessageView } from '../message';
|
|
19
|
+
import {
|
|
20
|
+
Attribute,
|
|
21
|
+
AttributeKey,
|
|
22
|
+
MessageHookPoints,
|
|
23
|
+
MessageHookPointsStatus,
|
|
24
|
+
MessageInterceptor,
|
|
25
|
+
MessageInterceptorContextImpl,
|
|
26
|
+
} from '../hook';
|
|
19
27
|
import { ConsumeResult } from './ConsumeResult';
|
|
20
28
|
import { MessageListener } from './MessageListener';
|
|
21
29
|
|
|
30
|
+
// Context keys exposed to interceptors, mirroring the Java ConsumeTask keys.
|
|
31
|
+
export const REMOTE_ADDR_CONTEXT_KEY = AttributeKey.create<string>('remoteAddr');
|
|
32
|
+
export const MESSAGE_VIEW_CONTEXT_KEY = AttributeKey.create<MessageView>('messageView');
|
|
33
|
+
export const CONSUMER_GROUP_CONTEXT_KEY = AttributeKey.create<string>('consumerGroup');
|
|
34
|
+
export const CONSUME_ERROR_CONTEXT_KEY = AttributeKey.create<unknown>('consumeError');
|
|
35
|
+
|
|
22
36
|
export class ConsumeTask {
|
|
23
37
|
readonly #messageListener: MessageListener;
|
|
24
38
|
readonly #messageView: MessageView;
|
|
39
|
+
readonly #consumerGroup?: string;
|
|
40
|
+
readonly #messageInterceptor?: MessageInterceptor;
|
|
25
41
|
|
|
26
|
-
constructor(_clientId: string, messageListener: MessageListener, messageView: MessageView
|
|
42
|
+
constructor(_clientId: string, messageListener: MessageListener, messageView: MessageView,
|
|
43
|
+
messageInterceptor?: MessageInterceptor, consumerGroup?: string) {
|
|
27
44
|
this.#messageListener = messageListener;
|
|
28
45
|
this.#messageView = messageView;
|
|
46
|
+
this.#messageInterceptor = messageInterceptor;
|
|
47
|
+
this.#consumerGroup = consumerGroup;
|
|
29
48
|
}
|
|
30
49
|
|
|
31
50
|
async call(): Promise<ConsumeResult> {
|
|
51
|
+
const generalMessages = [ this.#messageView ];
|
|
52
|
+
let context = new MessageInterceptorContextImpl(MessageHookPoints.CONSUME);
|
|
53
|
+
context.putAttribute(MESSAGE_VIEW_CONTEXT_KEY, Attribute.create(this.#messageView));
|
|
54
|
+
if (this.#consumerGroup) {
|
|
55
|
+
context.putAttribute(CONSUMER_GROUP_CONTEXT_KEY, Attribute.create(this.#consumerGroup));
|
|
56
|
+
}
|
|
57
|
+
let throwable: unknown;
|
|
58
|
+
let consumeResult: ConsumeResult;
|
|
59
|
+
if (this.#messageInterceptor) {
|
|
60
|
+
this.#messageInterceptor.doBefore(context, generalMessages);
|
|
61
|
+
}
|
|
32
62
|
try {
|
|
33
|
-
|
|
63
|
+
consumeResult = await this.#messageListener.consume(this.#messageView);
|
|
34
64
|
} catch (e) {
|
|
35
65
|
// Message listener raised an exception while consuming messages
|
|
36
|
-
|
|
66
|
+
throwable = e;
|
|
67
|
+
consumeResult = ConsumeResult.FAILURE;
|
|
68
|
+
}
|
|
69
|
+
const status = consumeResult === ConsumeResult.SUCCESS ? MessageHookPointsStatus.OK : MessageHookPointsStatus.ERROR;
|
|
70
|
+
context = MessageInterceptorContextImpl.withStatus(context, status);
|
|
71
|
+
if (throwable) {
|
|
72
|
+
context.putAttribute(CONSUME_ERROR_CONTEXT_KEY, Attribute.create(throwable));
|
|
73
|
+
}
|
|
74
|
+
if (this.#messageInterceptor) {
|
|
75
|
+
this.#messageInterceptor.doAfter(context, generalMessages);
|
|
37
76
|
}
|
|
77
|
+
return consumeResult;
|
|
38
78
|
}
|
|
39
79
|
}
|
package/src/consumer/Consumer.ts
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import { Message, Status } from '../../proto/apache/rocketmq/v2/definition_pb';
|
|
18
|
+
import { Code, Message, Status } from '../../proto/apache/rocketmq/v2/definition_pb';
|
|
19
19
|
import {
|
|
20
20
|
AckMessageRequest,
|
|
21
21
|
ChangeInvisibleDurationRequest,
|
|
@@ -25,8 +25,16 @@ import { ClientType } from '../../proto/apache/rocketmq/v2/definition_pb';
|
|
|
25
25
|
import { MessageView } from '../message';
|
|
26
26
|
import { MessageQueue } from '../route';
|
|
27
27
|
import { StatusChecker } from '../exception';
|
|
28
|
+
import { checkReceiveStatus } from '../exception/receiveStatus';
|
|
29
|
+
import { getRequestId } from '../util/rpcContext';
|
|
28
30
|
import { BaseClient, BaseClientOptions } from '../client';
|
|
29
31
|
import { createDuration, createResource } from '../util';
|
|
32
|
+
import {
|
|
33
|
+
GeneralMessage,
|
|
34
|
+
MessageHookPoints,
|
|
35
|
+
MessageHookPointsStatus,
|
|
36
|
+
MessageInterceptorContextImpl,
|
|
37
|
+
} from '../hook';
|
|
30
38
|
import { FilterExpression } from './FilterExpression';
|
|
31
39
|
|
|
32
40
|
export interface ConsumerOptions extends BaseClientOptions {
|
|
@@ -44,7 +52,7 @@ export abstract class Consumer extends BaseClient {
|
|
|
44
52
|
protected wrapReceiveMessageRequest(batchSize: number, mq: MessageQueue,
|
|
45
53
|
filterExpression: FilterExpression, invisibleDuration: number, longPollingTimeout: number) {
|
|
46
54
|
return new ReceiveMessageRequest()
|
|
47
|
-
.setGroup(createResource(this.consumerGroup))
|
|
55
|
+
.setGroup(createResource(this.consumerGroup, this.namespace))
|
|
48
56
|
.setMessageQueue(mq.toProtobuf())
|
|
49
57
|
.setFilterExpression(filterExpression.toProtobuf())
|
|
50
58
|
.setLongPollingTimeout(createDuration(longPollingTimeout))
|
|
@@ -58,9 +66,15 @@ export abstract class Consumer extends BaseClient {
|
|
|
58
66
|
const timeout = this.requestTimeout + awaitDuration;
|
|
59
67
|
let status: Status.AsObject | undefined;
|
|
60
68
|
|
|
69
|
+
// RECEIVE hook point, mirroring Java ProcessQueueImpl: intercept before the
|
|
70
|
+
// RPC so that interceptors which count in-flight requests observe the real
|
|
71
|
+
// request, and carry this same context into doAfter.
|
|
72
|
+
const context = new MessageInterceptorContextImpl(MessageHookPoints.RECEIVE);
|
|
73
|
+
this.doBefore(context, []);
|
|
74
|
+
|
|
61
75
|
try {
|
|
62
76
|
this.logger.debug?.('Receiving messages from broker, topic=%s, endpoints=%s, batchSize=%d, clientId=%s',
|
|
63
|
-
request.getMessageQueue()?.getTopic()?.getName(), endpoints, request.getBatchSize(),
|
|
77
|
+
request.getMessageQueue()?.getTopic()?.getName(), endpoints, request.getBatchSize(), this.clientId);
|
|
64
78
|
|
|
65
79
|
const responses = await this.rpcClientManager.receiveMessage(endpoints, request, timeout);
|
|
66
80
|
const messageList: Message[] = [];
|
|
@@ -78,23 +92,25 @@ export abstract class Consumer extends BaseClient {
|
|
|
78
92
|
transportDeliveryTimestamp = response.getDeliveryTimestamp()?.toDate();
|
|
79
93
|
break;
|
|
80
94
|
default:
|
|
81
|
-
|
|
82
|
-
|
|
95
|
+
this.logger.warn('Not recognized content for receive message response, mq=%s, clientId=%s, response=%j',
|
|
96
|
+
mq, this.clientId, response.toObject());
|
|
83
97
|
}
|
|
84
98
|
}
|
|
85
99
|
|
|
86
|
-
|
|
100
|
+
checkReceiveStatus(status, getRequestId(responses));
|
|
87
101
|
|
|
88
102
|
if (messageList.length > 0) {
|
|
89
103
|
this.logger.debug?.('Received %d messages successfully, topic=%s, endpoints=%s, clientId=%s',
|
|
90
|
-
messageList.length, request.getMessageQueue()?.getTopic()?.getName(), endpoints,
|
|
104
|
+
messageList.length, request.getMessageQueue()?.getTopic()?.getName(), endpoints, this.clientId);
|
|
91
105
|
}
|
|
92
106
|
|
|
93
107
|
const messages = messageList.map(message => new MessageView(message, mq, transportDeliveryTimestamp));
|
|
108
|
+
this.doAfter(MessageInterceptorContextImpl.withStatus(context, MessageHookPointsStatus.OK), messages);
|
|
94
109
|
return messages;
|
|
95
110
|
} catch (err) {
|
|
96
111
|
this.logger.error('Failed to receive messages, topic=%s, endpoints=%s, clientId=%s, error=%s',
|
|
97
|
-
request.getMessageQueue()?.getTopic()?.getName(), endpoints,
|
|
112
|
+
request.getMessageQueue()?.getTopic()?.getName(), endpoints, this.clientId, err);
|
|
113
|
+
this.doAfter(MessageInterceptorContextImpl.withStatus(context, MessageHookPointsStatus.ERROR), []);
|
|
98
114
|
throw err;
|
|
99
115
|
}
|
|
100
116
|
}
|
|
@@ -102,48 +118,113 @@ export abstract class Consumer extends BaseClient {
|
|
|
102
118
|
protected async ackMessage(messageView: MessageView) {
|
|
103
119
|
const endpoints = messageView.endpoints;
|
|
104
120
|
const request = new AckMessageRequest()
|
|
105
|
-
.setGroup(createResource(this.consumerGroup))
|
|
106
|
-
.setTopic(createResource(messageView.topic));
|
|
107
|
-
request.addEntries()
|
|
121
|
+
.setGroup(createResource(this.consumerGroup, this.namespace))
|
|
122
|
+
.setTopic(createResource(messageView.topic, this.namespace));
|
|
123
|
+
const entry = request.addEntries()
|
|
108
124
|
.setMessageId(messageView.messageId)
|
|
109
125
|
.setReceiptHandle(messageView.receiptHandle);
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
126
|
+
if (this.isLiteConsumer() && messageView.liteTopic) {
|
|
127
|
+
entry.setLiteTopic(messageView.liteTopic);
|
|
128
|
+
}
|
|
129
|
+
// ACK hook point, mirroring Java ConsumerImpl#ackMessage.
|
|
130
|
+
const context = new MessageInterceptorContextImpl(MessageHookPoints.ACK);
|
|
131
|
+
const generalMessages = [ messageView ];
|
|
132
|
+
this.doBefore(context, generalMessages);
|
|
133
|
+
let hookStatus = MessageHookPointsStatus.OK;
|
|
134
|
+
try {
|
|
135
|
+
const res = await this.rpcClientManager.ackMessage(endpoints, request, this.requestTimeout);
|
|
136
|
+
const response = res.toObject();
|
|
137
|
+
hookStatus = response.status?.code === Code.OK ? MessageHookPointsStatus.OK : MessageHookPointsStatus.ERROR;
|
|
138
|
+
StatusChecker.check(response.status, getRequestId(res));
|
|
139
|
+
this.doAfter(MessageInterceptorContextImpl.withStatus(context, hookStatus), generalMessages);
|
|
140
|
+
return response.entriesList;
|
|
141
|
+
} catch (err) {
|
|
142
|
+
this.doAfter(MessageInterceptorContextImpl.withStatus(context, MessageHookPointsStatus.ERROR), generalMessages);
|
|
143
|
+
throw err;
|
|
144
|
+
}
|
|
115
145
|
}
|
|
116
146
|
|
|
117
147
|
protected async invisibleDuration(messageView: MessageView, invisibleDuration: number) {
|
|
118
148
|
const request = new ChangeInvisibleDurationRequest()
|
|
119
|
-
.setGroup(createResource(this.consumerGroup))
|
|
120
|
-
.setTopic(createResource(messageView.topic))
|
|
149
|
+
.setGroup(createResource(this.consumerGroup, this.namespace))
|
|
150
|
+
.setTopic(createResource(messageView.topic, this.namespace))
|
|
121
151
|
.setReceiptHandle(messageView.receiptHandle)
|
|
122
152
|
.setInvisibleDuration(createDuration(invisibleDuration))
|
|
123
153
|
.setMessageId(messageView.messageId);
|
|
154
|
+
if (this.isLiteConsumer() && messageView.liteTopic) {
|
|
155
|
+
request.setLiteTopic(messageView.liteTopic);
|
|
156
|
+
}
|
|
124
157
|
|
|
125
|
-
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
158
|
+
// CHANGE_INVISIBLE_DURATION hook point, mirroring Java ConsumerImpl#changeInvisibleDuration.
|
|
159
|
+
const context = new MessageInterceptorContextImpl(MessageHookPoints.CHANGE_INVISIBLE_DURATION);
|
|
160
|
+
const generalMessages = [ messageView ];
|
|
161
|
+
this.doBefore(context, generalMessages);
|
|
162
|
+
let hookStatus = MessageHookPointsStatus.OK;
|
|
163
|
+
try {
|
|
164
|
+
const res = await this.rpcClientManager.changeInvisibleDuration(messageView.endpoints, request, this.requestTimeout);
|
|
165
|
+
const response = res.toObject();
|
|
166
|
+
hookStatus = response.status?.code === Code.OK ? MessageHookPointsStatus.OK : MessageHookPointsStatus.ERROR;
|
|
167
|
+
StatusChecker.check(response.status, getRequestId(res));
|
|
168
|
+
this.doAfter(MessageInterceptorContextImpl.withStatus(context, hookStatus), generalMessages);
|
|
169
|
+
return response.receiptHandle;
|
|
170
|
+
} catch (err) {
|
|
171
|
+
this.doAfter(MessageInterceptorContextImpl.withStatus(context, MessageHookPointsStatus.ERROR), generalMessages);
|
|
172
|
+
throw err;
|
|
173
|
+
}
|
|
129
174
|
}
|
|
130
175
|
|
|
131
176
|
/**
|
|
132
|
-
* Expose public methods for ProcessQueue to access RPC operations
|
|
177
|
+
* Expose public methods for ProcessQueue to access RPC operations. Each attempt
|
|
178
|
+
* — including retries driven by ProcessQueue — triggers the matching hook point,
|
|
179
|
+
* so PushConsumer and SimpleConsumer observability stays consistent.
|
|
133
180
|
*/
|
|
134
|
-
async ackMessageViaRpc(endpoints: any, request: AckMessageRequest, timeout: number) {
|
|
135
|
-
|
|
136
|
-
|
|
181
|
+
async ackMessageViaRpc(endpoints: any, request: AckMessageRequest, timeout: number, messageView: MessageView) {
|
|
182
|
+
return this.#invokeWithHook(
|
|
183
|
+
MessageHookPoints.ACK,
|
|
184
|
+
messageView,
|
|
185
|
+
() => this.rpcClientManager.ackMessage(endpoints, request, timeout),
|
|
186
|
+
);
|
|
137
187
|
}
|
|
138
188
|
|
|
139
|
-
async changeInvisibleDurationViaRpc(endpoints: any, request: ChangeInvisibleDurationRequest, timeout: number
|
|
140
|
-
|
|
141
|
-
return
|
|
189
|
+
async changeInvisibleDurationViaRpc(endpoints: any, request: ChangeInvisibleDurationRequest, timeout: number,
|
|
190
|
+
messageView: MessageView) {
|
|
191
|
+
return this.#invokeWithHook(
|
|
192
|
+
MessageHookPoints.CHANGE_INVISIBLE_DURATION,
|
|
193
|
+
messageView,
|
|
194
|
+
() => this.rpcClientManager.changeInvisibleDuration(endpoints, request, timeout),
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
async #invokeWithHook<T extends { getStatus(): Status | undefined }>(hookPoint: MessageHookPoints,
|
|
199
|
+
messageView: MessageView,
|
|
200
|
+
rpc: () => Promise<T>): Promise<T> {
|
|
201
|
+
const context = new MessageInterceptorContextImpl(hookPoint);
|
|
202
|
+
const generalMessages: GeneralMessage[] = [ messageView ];
|
|
203
|
+
this.doBefore(context, generalMessages);
|
|
204
|
+
try {
|
|
205
|
+
const response = await rpc();
|
|
206
|
+
const hookStatus = response.getStatus()?.getCode() === Code.OK
|
|
207
|
+
? MessageHookPointsStatus.OK : MessageHookPointsStatus.ERROR;
|
|
208
|
+
this.doAfter(MessageInterceptorContextImpl.withStatus(context, hookStatus), generalMessages);
|
|
209
|
+
return response;
|
|
210
|
+
} catch (err) {
|
|
211
|
+
this.doAfter(MessageInterceptorContextImpl.withStatus(context, MessageHookPointsStatus.ERROR), generalMessages);
|
|
212
|
+
throw err;
|
|
213
|
+
}
|
|
142
214
|
}
|
|
143
215
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
216
|
+
/**
|
|
217
|
+
* Forward the message to the dead letter queue, mirroring Java
|
|
218
|
+
* PushConsumerImpl#forwardMessageToDeadLetterQueue. The FORWARD_TO_DLQ hook
|
|
219
|
+
* point is triggered around every RPC attempt.
|
|
220
|
+
*/
|
|
221
|
+
async forwardMessageToDeadLetterQueueViaRpc(endpoints: any, request: any, timeout: number,
|
|
222
|
+
messageView: MessageView) {
|
|
223
|
+
return this.#invokeWithHook(
|
|
224
|
+
MessageHookPoints.FORWARD_TO_DLQ,
|
|
225
|
+
messageView,
|
|
226
|
+
() => this.rpcClientManager.forwardMessageToDeadLetterQueue(endpoints, request, timeout),
|
|
227
|
+
);
|
|
147
228
|
}
|
|
148
229
|
|
|
149
230
|
/**
|
|
@@ -158,10 +239,10 @@ export abstract class Consumer extends BaseClient {
|
|
|
158
239
|
/**
|
|
159
240
|
* Check if this is a lite consumer.
|
|
160
241
|
*
|
|
161
|
-
* @return true if this is a LITE_PUSH_CONSUMER
|
|
242
|
+
* @return true if this is a LITE_PUSH_CONSUMER or LITE_SIMPLE_CONSUMER
|
|
162
243
|
*/
|
|
163
244
|
protected isLiteConsumer(): boolean {
|
|
164
|
-
const clientType =
|
|
165
|
-
return clientType === ClientType.LITE_PUSH_CONSUMER;
|
|
245
|
+
const clientType = this.getClientType();
|
|
246
|
+
return clientType === ClientType.LITE_PUSH_CONSUMER || clientType === ClientType.LITE_SIMPLE_CONSUMER;
|
|
166
247
|
}
|
|
167
248
|
}
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
import { MessageView } from '../message';
|
|
19
|
+
import { MessageInterceptor } from '../hook';
|
|
19
20
|
import { ConsumeService } from './ConsumeService';
|
|
20
21
|
import { MessageListener } from './MessageListener';
|
|
21
22
|
import type { ProcessQueue } from './ProcessQueue';
|
|
@@ -25,10 +26,11 @@ export class FifoConsumeService extends ConsumeService {
|
|
|
25
26
|
readonly #enableFifoConsumeAccelerator: boolean;
|
|
26
27
|
readonly #logger: ILogger;
|
|
27
28
|
|
|
28
|
-
constructor(clientId: string, messageListener: MessageListener, enableFifoConsumeAccelerator?: boolean
|
|
29
|
-
|
|
29
|
+
constructor(clientId: string, messageListener: MessageListener, enableFifoConsumeAccelerator?: boolean,
|
|
30
|
+
messageInterceptor?: MessageInterceptor, consumerGroup?: string, logger?: ILogger) {
|
|
31
|
+
super(clientId, messageListener, messageInterceptor, consumerGroup);
|
|
30
32
|
this.#enableFifoConsumeAccelerator = enableFifoConsumeAccelerator ?? false;
|
|
31
|
-
this.#logger = getDefaultLogger();
|
|
33
|
+
this.#logger = logger ?? getDefaultLogger();
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
consume(pq: ProcessQueue, messageViews: MessageView[]): void {
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
3
|
+
* contributor license agreements. See the NOTICE file distributed with
|
|
4
|
+
* this work for additional information regarding copyright ownership.
|
|
5
|
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
6
|
+
* (the "License"); you may not use this file except in compliance with
|
|
7
|
+
* the License. You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { LiteSubscriptionManager } from './LiteSubscriptionManager';
|
|
19
|
+
import { OffsetOption } from './OffsetOption';
|
|
20
|
+
|
|
21
|
+
// Both Lite consumers share lifecycle ordering and entry validation; callers supply parent operations.
|
|
22
|
+
// Keep this helper out of consumer/index.ts exports and preserve existing Impl and manager entry points.
|
|
23
|
+
export class LiteConsumerSupport extends LiteSubscriptionManager {
|
|
24
|
+
async startConsumer(startParent: () => Promise<void>): Promise<void> {
|
|
25
|
+
await startParent();
|
|
26
|
+
this.startUp();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async shutdownConsumer(shutdownParent: () => Promise<void>): Promise<void> {
|
|
30
|
+
this.shutdown();
|
|
31
|
+
await shutdownParent();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async subscribeLite(liteTopic: string, offsetOption?: OffsetOption | null): Promise<void> {
|
|
35
|
+
this.validateArgument(liteTopic);
|
|
36
|
+
await super.subscribeLite(liteTopic, offsetOption ?? null);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async unsubscribeLite(liteTopic: string): Promise<void> {
|
|
40
|
+
this.validateArgument(liteTopic);
|
|
41
|
+
await super.unsubscribeLite(liteTopic);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private validateArgument(liteTopic: string): void {
|
|
45
|
+
if (!liteTopic || liteTopic.trim().length === 0) {
|
|
46
|
+
throw new Error('liteTopic should not be blank');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
import { MessageView } from '../message';
|
|
19
|
+
import { MessageInterceptor } from '../hook';
|
|
19
20
|
import { ConsumeResultSuspend } from './ConsumeResult';
|
|
20
21
|
import { FifoConsumeService } from './FifoConsumeService';
|
|
21
22
|
import { MessageListener } from './MessageListener';
|
|
@@ -37,9 +38,10 @@ import { ILogger, getDefaultLogger } from '../client/Logger';
|
|
|
37
38
|
export class LiteFifoConsumeService extends FifoConsumeService {
|
|
38
39
|
readonly #logger: ILogger;
|
|
39
40
|
|
|
40
|
-
constructor(clientId: string, messageListener: MessageListener, enableFifoConsumeAccelerator?: boolean
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
constructor(clientId: string, messageListener: MessageListener, enableFifoConsumeAccelerator?: boolean,
|
|
42
|
+
messageInterceptor?: MessageInterceptor, consumerGroup?: string, logger?: ILogger) {
|
|
43
|
+
super(clientId, messageListener, enableFifoConsumeAccelerator, messageInterceptor, consumerGroup, logger);
|
|
44
|
+
this.#logger = logger ?? getDefaultLogger();
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
/**
|