rocketmq-client-nodejs 1.0.7 → 1.1.0

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 (164) hide show
  1. package/README.md +61 -0
  2. package/dist/client/BaseClient.d.ts +36 -1
  3. package/dist/client/BaseClient.js +176 -12
  4. package/dist/client/RpcClient.js +14 -2
  5. package/dist/client/RpcClientManager.d.ts +5 -0
  6. package/dist/client/RpcClientManager.js +25 -8
  7. package/dist/client/TelemetrySession.js +45 -10
  8. package/dist/consumer/ConsumeResult.d.ts +2 -2
  9. package/dist/consumer/ConsumeResult.js +6 -3
  10. package/dist/consumer/ConsumeService.d.ts +2 -1
  11. package/dist/consumer/ConsumeService.js +7 -3
  12. package/dist/consumer/ConsumeTask.d.ts +6 -1
  13. package/dist/consumer/ConsumeTask.js +36 -5
  14. package/dist/consumer/Consumer.d.ts +13 -5
  15. package/dist/consumer/Consumer.js +85 -24
  16. package/dist/consumer/FifoConsumeService.d.ts +2 -1
  17. package/dist/consumer/FifoConsumeService.js +3 -3
  18. package/dist/consumer/LiteFifoConsumeService.d.ts +2 -1
  19. package/dist/consumer/LiteFifoConsumeService.js +3 -3
  20. package/dist/consumer/LitePushConsumerImpl.d.ts +12 -1
  21. package/dist/consumer/LitePushConsumerImpl.js +19 -4
  22. package/dist/consumer/LiteSimpleConsumer.d.ts +177 -0
  23. package/dist/consumer/LiteSimpleConsumer.js +126 -0
  24. package/dist/consumer/LiteSimpleConsumerImpl.d.ts +133 -0
  25. package/dist/consumer/LiteSimpleConsumerImpl.js +187 -0
  26. package/dist/consumer/LiteStandardConsumeService.d.ts +2 -1
  27. package/dist/consumer/LiteStandardConsumeService.js +3 -3
  28. package/dist/consumer/LiteSubscriptionManager.d.ts +27 -6
  29. package/dist/consumer/LiteSubscriptionManager.js +32 -24
  30. package/dist/consumer/ProcessQueue.d.ts +10 -0
  31. package/dist/consumer/ProcessQueue.js +47 -7
  32. package/dist/consumer/PushConsumer.d.ts +17 -0
  33. package/dist/consumer/PushConsumer.js +87 -7
  34. package/dist/consumer/PushConsumerGaugeObserver.d.ts +33 -0
  35. package/dist/consumer/PushConsumerGaugeObserver.js +60 -0
  36. package/dist/consumer/PushSubscriptionSettings.d.ts +8 -1
  37. package/dist/consumer/PushSubscriptionSettings.js +33 -6
  38. package/dist/consumer/SimpleConsumer.js +10 -1
  39. package/dist/consumer/StandardConsumeService.d.ts +2 -1
  40. package/dist/consumer/StandardConsumeService.js +3 -3
  41. package/dist/consumer/index.d.ts +1 -0
  42. package/dist/consumer/index.js +2 -1
  43. package/dist/exception/PayloadEmptyException.d.ts +20 -0
  44. package/dist/exception/PayloadEmptyException.js +28 -0
  45. package/dist/exception/StatusChecker.js +8 -1
  46. package/dist/exception/index.d.ts +1 -0
  47. package/dist/exception/index.js +2 -1
  48. package/dist/hook/Attribute.d.ts +26 -0
  49. package/dist/hook/Attribute.js +37 -0
  50. package/dist/hook/AttributeKey.d.ts +32 -0
  51. package/dist/hook/AttributeKey.js +43 -0
  52. package/dist/hook/CompositedMessageInterceptor.d.ts +31 -0
  53. package/dist/hook/CompositedMessageInterceptor.js +84 -0
  54. package/dist/hook/InflightRequestCountInterceptor.d.ts +28 -0
  55. package/dist/hook/InflightRequestCountInterceptor.js +44 -0
  56. package/dist/hook/MessageHookPoints.d.ts +54 -0
  57. package/dist/hook/MessageHookPoints.js +59 -0
  58. package/dist/hook/MessageHookPointsStatus.d.ts +24 -0
  59. package/dist/hook/MessageHookPointsStatus.js +29 -0
  60. package/dist/hook/MessageInterceptor.d.ts +34 -0
  61. package/dist/hook/MessageInterceptor.js +19 -0
  62. package/dist/hook/MessageInterceptorContext.d.ts +31 -0
  63. package/dist/hook/MessageInterceptorContext.js +19 -0
  64. package/dist/hook/MessageInterceptorContextImpl.d.ts +39 -0
  65. package/dist/hook/MessageInterceptorContextImpl.js +57 -0
  66. package/dist/hook/MessageMeterInterceptor.d.ts +39 -0
  67. package/dist/hook/MessageMeterInterceptor.js +149 -0
  68. package/dist/hook/index.d.ts +26 -0
  69. package/dist/hook/index.js +43 -0
  70. package/dist/index.d.ts +1 -0
  71. package/dist/index.js +2 -1
  72. package/dist/metrics/ClientMeter.d.ts +42 -0
  73. package/dist/metrics/ClientMeter.js +75 -0
  74. package/dist/metrics/ClientMeterManager.d.ts +42 -0
  75. package/dist/metrics/ClientMeterManager.js +127 -0
  76. package/dist/metrics/EmptyGaugeObserver.d.ts +28 -0
  77. package/dist/metrics/EmptyGaugeObserver.js +34 -0
  78. package/dist/metrics/GaugeEnum.d.ts +32 -0
  79. package/dist/metrics/GaugeEnum.js +37 -0
  80. package/dist/metrics/GaugeObserver.d.ts +29 -0
  81. package/dist/metrics/GaugeObserver.js +19 -0
  82. package/dist/metrics/HistogramEnum.d.ts +54 -0
  83. package/dist/metrics/HistogramEnum.js +71 -0
  84. package/dist/metrics/InvocationStatus.d.ts +26 -0
  85. package/dist/metrics/InvocationStatus.js +33 -0
  86. package/dist/metrics/Metric.d.ts +30 -0
  87. package/dist/metrics/Metric.js +44 -0
  88. package/dist/metrics/MetricLabels.d.ts +27 -0
  89. package/dist/metrics/MetricLabels.js +34 -0
  90. package/dist/metrics/index.d.ts +25 -0
  91. package/dist/metrics/index.js +42 -0
  92. package/dist/producer/Producer.js +33 -5
  93. package/dist/producer/PublishingLoadBalancer.js +9 -3
  94. package/dist/retry/CustomizedBackoffRetryPolicy.d.ts +37 -0
  95. package/dist/retry/CustomizedBackoffRetryPolicy.js +72 -0
  96. package/dist/retry/ExponentialBackoffRetryPolicy.js +10 -6
  97. package/dist/retry/RetryPolicy.d.ts +1 -1
  98. package/dist/retry/index.d.ts +1 -0
  99. package/dist/retry/index.js +2 -1
  100. package/dist/route/Endpoints.d.ts +6 -0
  101. package/dist/route/Endpoints.js +56 -4
  102. package/dist/route/IpNameResolver.d.ts +28 -0
  103. package/dist/route/IpNameResolver.js +104 -0
  104. package/dist/util/Semaphore.d.ts +47 -0
  105. package/dist/util/Semaphore.js +82 -0
  106. package/dist/util/index.js +6 -3
  107. package/package.json +6 -2
  108. package/src/client/BaseClient.ts +202 -12
  109. package/src/client/RpcClient.ts +14 -1
  110. package/src/client/RpcClientManager.ts +27 -8
  111. package/src/client/TelemetrySession.ts +47 -9
  112. package/src/consumer/ConsumeResult.ts +5 -2
  113. package/src/consumer/ConsumeService.ts +9 -2
  114. package/src/consumer/ConsumeTask.ts +43 -3
  115. package/src/consumer/Consumer.ts +103 -23
  116. package/src/consumer/FifoConsumeService.ts +4 -2
  117. package/src/consumer/LiteFifoConsumeService.ts +4 -2
  118. package/src/consumer/LitePushConsumerImpl.ts +21 -3
  119. package/src/consumer/LiteSimpleConsumer.ts +251 -0
  120. package/src/consumer/LiteSimpleConsumerImpl.ts +221 -0
  121. package/src/consumer/LiteStandardConsumeService.ts +4 -2
  122. package/src/consumer/LiteSubscriptionManager.ts +63 -36
  123. package/src/consumer/ProcessQueue.ts +54 -3
  124. package/src/consumer/PushConsumer.ts +98 -5
  125. package/src/consumer/PushConsumerGaugeObserver.ts +60 -0
  126. package/src/consumer/PushSubscriptionSettings.ts +38 -7
  127. package/src/consumer/SimpleConsumer.ts +9 -0
  128. package/src/consumer/StandardConsumeService.ts +4 -2
  129. package/src/consumer/index.ts +1 -0
  130. package/src/exception/PayloadEmptyException.ts +25 -0
  131. package/src/exception/StatusChecker.ts +7 -0
  132. package/src/exception/index.ts +1 -0
  133. package/src/hook/Attribute.ts +36 -0
  134. package/src/hook/AttributeKey.ts +42 -0
  135. package/src/hook/CompositedMessageInterceptor.ts +92 -0
  136. package/src/hook/InflightRequestCountInterceptor.ts +46 -0
  137. package/src/hook/MessageHookPoints.ts +55 -0
  138. package/src/hook/MessageHookPointsStatus.ts +25 -0
  139. package/src/hook/MessageInterceptor.ts +35 -0
  140. package/src/hook/MessageInterceptorContext.ts +33 -0
  141. package/src/hook/MessageInterceptorContextImpl.ts +68 -0
  142. package/src/hook/MessageMeterInterceptor.ts +162 -0
  143. package/src/hook/index.ts +27 -0
  144. package/src/index.ts +1 -0
  145. package/src/metrics/ClientMeter.ts +81 -0
  146. package/src/metrics/ClientMeterManager.ts +145 -0
  147. package/src/metrics/EmptyGaugeObserver.ts +36 -0
  148. package/src/metrics/GaugeEnum.ts +33 -0
  149. package/src/metrics/GaugeObserver.ts +32 -0
  150. package/src/metrics/HistogramEnum.ts +69 -0
  151. package/src/metrics/InvocationStatus.ts +28 -0
  152. package/src/metrics/Metric.ts +42 -0
  153. package/src/metrics/MetricLabels.ts +31 -0
  154. package/src/metrics/index.ts +26 -0
  155. package/src/producer/Producer.ts +37 -6
  156. package/src/producer/PublishingLoadBalancer.ts +8 -2
  157. package/src/retry/CustomizedBackoffRetryPolicy.ts +81 -0
  158. package/src/retry/ExponentialBackoffRetryPolicy.ts +11 -6
  159. package/src/retry/RetryPolicy.ts +1 -1
  160. package/src/retry/index.ts +1 -0
  161. package/src/route/Endpoints.ts +52 -3
  162. package/src/route/IpNameResolver.ts +119 -0
  163. package/src/util/Semaphore.ts +82 -0
  164. package/src/util/index.ts +5 -2
@@ -0,0 +1,34 @@
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
+ import { MessageView } from '../message/MessageView';
18
+ import { MessageInterceptorContext } from './MessageInterceptorContext';
19
+ /**
20
+ * Message passed to interceptors: either an outgoing message or a received one,
21
+ * mirroring org.apache.rocketmq.client.java.message.GeneralMessage.
22
+ */
23
+ export type GeneralMessage = MessageView | {
24
+ topic: string;
25
+ };
26
+ /**
27
+ * Interface for intercepting ingoing/outgoing message before/after they are
28
+ * dispatched by client, mirroring
29
+ * org.apache.rocketmq.client.java.hook.MessageInterceptor.
30
+ */
31
+ export interface MessageInterceptor {
32
+ doBefore(context: MessageInterceptorContext, messages: GeneralMessage[]): void;
33
+ doAfter(context: MessageInterceptorContext, messages: GeneralMessage[]): void;
34
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ /**
3
+ * Licensed to the Apache Software Foundation (ASF) under one or more
4
+ * contributor license agreements. See the NOTICE file distributed with
5
+ * this work for additional information regarding copyright ownership.
6
+ * The ASF licenses this file to You under the Apache License, Version 2.0
7
+ * (the "License"); you may not use this file except in compliance with
8
+ * the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTWVzc2FnZUludGVyY2VwdG9yLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2hvb2svTWVzc2FnZUludGVyY2VwdG9yLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQTs7Ozs7Ozs7Ozs7Ozs7O0dBZUcifQ==
@@ -0,0 +1,31 @@
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
+ import { Attribute } from './Attribute';
18
+ import { AttributeKey } from './AttributeKey';
19
+ import { MessageHookPoints } from './MessageHookPoints';
20
+ import { MessageHookPointsStatus } from './MessageHookPointsStatus';
21
+ /**
22
+ * Context carried through the message interceptor chain, mirroring
23
+ * org.apache.rocketmq.client.java.hook.MessageInterceptorContext.
24
+ */
25
+ export interface MessageInterceptorContext {
26
+ getMessageHookPoints(): MessageHookPoints;
27
+ getStatus(): MessageHookPointsStatus | undefined;
28
+ putAttribute<T>(key: AttributeKey<T>, value: Attribute<T>): void;
29
+ getAttribute<T>(key: AttributeKey<T>): Attribute<T> | undefined;
30
+ getAttributes(): Map<AttributeKey<any>, Attribute<any>>;
31
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ /**
3
+ * Licensed to the Apache Software Foundation (ASF) under one or more
4
+ * contributor license agreements. See the NOTICE file distributed with
5
+ * this work for additional information regarding copyright ownership.
6
+ * The ASF licenses this file to You under the Apache License, Version 2.0
7
+ * (the "License"); you may not use this file except in compliance with
8
+ * the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTWVzc2FnZUludGVyY2VwdG9yQ29udGV4dC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ob29rL01lc3NhZ2VJbnRlcmNlcHRvckNvbnRleHQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBOzs7Ozs7Ozs7Ozs7Ozs7R0FlRyJ9
@@ -0,0 +1,39 @@
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
+ import { Attribute } from './Attribute';
18
+ import { AttributeKey } from './AttributeKey';
19
+ import { MessageHookPoints } from './MessageHookPoints';
20
+ import { MessageHookPointsStatus } from './MessageHookPointsStatus';
21
+ import { MessageInterceptorContext } from './MessageInterceptorContext';
22
+ /**
23
+ * Default {@link MessageInterceptorContext} implementation, mirroring
24
+ * org.apache.rocketmq.client.java.hook.MessageInterceptorContextImpl.
25
+ */
26
+ export declare class MessageInterceptorContextImpl implements MessageInterceptorContext {
27
+ #private;
28
+ constructor(messageHookPoints: MessageHookPoints, status?: MessageHookPointsStatus, attributes?: Map<AttributeKey<any>, Attribute<any>>);
29
+ /**
30
+ * Derive a new context from an existing one with the given status, e.g. once the
31
+ * outcome of the intercepted operation is known.
32
+ */
33
+ static withStatus(context: MessageInterceptorContext, status: MessageHookPointsStatus): MessageInterceptorContextImpl;
34
+ getMessageHookPoints(): MessageHookPoints;
35
+ getStatus(): MessageHookPointsStatus | undefined;
36
+ putAttribute<T>(key: AttributeKey<T>, value: Attribute<T>): void;
37
+ getAttribute<T>(key: AttributeKey<T>): Attribute<T> | undefined;
38
+ getAttributes(): Map<AttributeKey<any>, Attribute<any>>;
39
+ }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ /**
3
+ * Licensed to the Apache Software Foundation (ASF) under one or more
4
+ * contributor license agreements. See the NOTICE file distributed with
5
+ * this work for additional information regarding copyright ownership.
6
+ * The ASF licenses this file to You under the Apache License, Version 2.0
7
+ * (the "License"); you may not use this file except in compliance with
8
+ * the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.MessageInterceptorContextImpl = void 0;
20
+ /**
21
+ * Default {@link MessageInterceptorContext} implementation, mirroring
22
+ * org.apache.rocketmq.client.java.hook.MessageInterceptorContextImpl.
23
+ */
24
+ class MessageInterceptorContextImpl {
25
+ #messageHookPoints;
26
+ #status;
27
+ #attributes;
28
+ constructor(messageHookPoints, status, attributes) {
29
+ this.#messageHookPoints = messageHookPoints;
30
+ this.#status = status;
31
+ this.#attributes = new Map(attributes ?? []);
32
+ }
33
+ /**
34
+ * Derive a new context from an existing one with the given status, e.g. once the
35
+ * outcome of the intercepted operation is known.
36
+ */
37
+ static withStatus(context, status) {
38
+ return new MessageInterceptorContextImpl(context.getMessageHookPoints(), status, context.getAttributes());
39
+ }
40
+ getMessageHookPoints() {
41
+ return this.#messageHookPoints;
42
+ }
43
+ getStatus() {
44
+ return this.#status;
45
+ }
46
+ putAttribute(key, value) {
47
+ this.#attributes.set(key, value);
48
+ }
49
+ getAttribute(key) {
50
+ return this.#attributes.get(key);
51
+ }
52
+ getAttributes() {
53
+ return this.#attributes;
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UFBWSxDQUFJLEdBQW9CLEVBQUUsS0FBbUI7UUFDdkQsSUFBSSxDQUFDLFdBQVcsQ0FBQyxHQUFHLENBQUMsR0FBRyxFQUFFLEtBQUssQ0FBQyxDQUFDO0lBQ25DLENBQUM7SUFFRCxZQUFZLENBQUksR0FBb0I7UUFDbEMsT0FBTyxJQUFJLENBQUMsV0FBVyxDQUFDLEdBQUcsQ0FBQyxHQUFHLENBQTZCLENBQUM7SUFDL0QsQ0FBQztJQUVELGFBQWE7UUFDWCxPQUFPLElBQUksQ0FBQyxXQUFXLENBQUM7SUFDMUIsQ0FBQztDQUNGO0FBeENELHNFQXdDQyJ9
@@ -0,0 +1,39 @@
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
+ import { AttributeKey, MessageInterceptor, MessageInterceptorContext } from './';
18
+ import { GeneralMessage } from './MessageInterceptor';
19
+ import { ClientMeterManager } from '../metrics/ClientMeterManager';
20
+ /**
21
+ * Records the four RocketMQ histograms around the SEND / RECEIVE / CONSUME hook
22
+ * points, mirroring org.apache.rocketmq.client.java.metrics.MessageMeterInterceptor.
23
+ *
24
+ * Unlike Java (which wires an AuthInterceptor + IpNameResolverFactory onto the
25
+ * export channel), the Node client signs each export request via a per-call
26
+ * metadata provider (see {@link ClientMeterManager}), so no auth plumbing is
27
+ * needed here.
28
+ */
29
+ export declare class MessageMeterInterceptor implements MessageInterceptor {
30
+ #private;
31
+ private readonly meterManager;
32
+ private readonly clientId;
33
+ private readonly getConsumerGroup;
34
+ static readonly SEND_STOPWATCH_KEY: AttributeKey<number>;
35
+ static readonly CONSUME_STOPWATCH_KEY: AttributeKey<number>;
36
+ constructor(meterManager: ClientMeterManager, clientId: string, getConsumerGroup: () => string | undefined);
37
+ doBefore(context: MessageInterceptorContext, messages: GeneralMessage[]): void;
38
+ doAfter(context: MessageInterceptorContext, messages: GeneralMessage[]): void;
39
+ }
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ /**
3
+ * Licensed to the Apache Software Foundation (ASF) under one or more
4
+ * contributor license agreements. See the NOTICE file distributed with
5
+ * this work for additional information regarding copyright ownership.
6
+ * The ASF licenses this file to You under the Apache License, Version 2.0
7
+ * (the "License"); you may not use this file except in compliance with
8
+ * the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.MessageMeterInterceptor = void 0;
20
+ const _1 = require("./");
21
+ const MetricLabels_1 = require("../metrics/MetricLabels");
22
+ const InvocationStatus_1 = require("../metrics/InvocationStatus");
23
+ const HistogramEnum_1 = require("../metrics/HistogramEnum");
24
+ /**
25
+ * Records the four RocketMQ histograms around the SEND / RECEIVE / CONSUME hook
26
+ * points, mirroring org.apache.rocketmq.client.java.metrics.MessageMeterInterceptor.
27
+ *
28
+ * Unlike Java (which wires an AuthInterceptor + IpNameResolverFactory onto the
29
+ * export channel), the Node client signs each export request via a per-call
30
+ * metadata provider (see {@link ClientMeterManager}), so no auth plumbing is
31
+ * needed here.
32
+ */
33
+ class MessageMeterInterceptor {
34
+ meterManager;
35
+ clientId;
36
+ getConsumerGroup;
37
+ static SEND_STOPWATCH_KEY = _1.AttributeKey.create('send_stopwatch');
38
+ static CONSUME_STOPWATCH_KEY = _1.AttributeKey.create('consume_stopwatch');
39
+ constructor(meterManager, clientId, getConsumerGroup) {
40
+ this.meterManager = meterManager;
41
+ this.clientId = clientId;
42
+ this.getConsumerGroup = getConsumerGroup;
43
+ }
44
+ doBefore(context, messages) {
45
+ if (!this.meterManager.isEnabled()) {
46
+ return;
47
+ }
48
+ switch (context.getMessageHookPoints()) {
49
+ case _1.MessageHookPoints.SEND:
50
+ context.putAttribute(MessageMeterInterceptor.SEND_STOPWATCH_KEY, _1.Attribute.create(Date.now()));
51
+ break;
52
+ case _1.MessageHookPoints.CONSUME: {
53
+ const consumerGroup = this.getConsumerGroup();
54
+ if (!consumerGroup) {
55
+ break;
56
+ }
57
+ const message = messages[0];
58
+ if (!message || !message.decodeTimestamp) {
59
+ break;
60
+ }
61
+ const latency = Date.now() - message.decodeTimestamp.getTime();
62
+ const attributes = this.#consumerAttributes(message.topic, consumerGroup);
63
+ this.meterManager.record(HistogramEnum_1.HistogramEnum.AWAIT_TIME, attributes, latency);
64
+ context.putAttribute(MessageMeterInterceptor.CONSUME_STOPWATCH_KEY, _1.Attribute.create(Date.now()));
65
+ break;
66
+ }
67
+ default:
68
+ break;
69
+ }
70
+ }
71
+ doAfter(context, messages) {
72
+ if (!this.meterManager.isEnabled()) {
73
+ return;
74
+ }
75
+ const status = context.getStatus();
76
+ const invocationStatus = status === _1.MessageHookPointsStatus.OK ? InvocationStatus_1.InvocationStatus.SUCCESS : InvocationStatus_1.InvocationStatus.FAILURE;
77
+ switch (context.getMessageHookPoints()) {
78
+ case _1.MessageHookPoints.SEND: {
79
+ const attr = context.getAttribute(MessageMeterInterceptor.SEND_STOPWATCH_KEY);
80
+ if (!attr) {
81
+ break;
82
+ }
83
+ const message = messages[0];
84
+ if (!message) {
85
+ break;
86
+ }
87
+ const cost = Date.now() - attr.get();
88
+ const attributes = {
89
+ [MetricLabels_1.MetricLabels.TOPIC]: message.topic,
90
+ [MetricLabels_1.MetricLabels.CLIENT_ID]: this.clientId,
91
+ [MetricLabels_1.MetricLabels.INVOCATION_STATUS]: invocationStatus.name,
92
+ };
93
+ this.meterManager.record(HistogramEnum_1.HistogramEnum.SEND_COST_TIME, attributes, cost);
94
+ break;
95
+ }
96
+ case _1.MessageHookPoints.RECEIVE: {
97
+ const consumerGroup = this.getConsumerGroup();
98
+ if (!consumerGroup) {
99
+ break;
100
+ }
101
+ const message = messages[0];
102
+ if (!message || !message.transportDeliveryTimestamp) {
103
+ break;
104
+ }
105
+ const latency = Date.now() - message.transportDeliveryTimestamp.getTime();
106
+ if (latency < 0) {
107
+ break;
108
+ }
109
+ const attributes = this.#consumerAttributes(message.topic, consumerGroup);
110
+ this.meterManager.record(HistogramEnum_1.HistogramEnum.DELIVERY_LATENCY, attributes, latency);
111
+ break;
112
+ }
113
+ case _1.MessageHookPoints.CONSUME: {
114
+ const consumerGroup = this.getConsumerGroup();
115
+ if (!consumerGroup) {
116
+ break;
117
+ }
118
+ const attr = context.getAttribute(MessageMeterInterceptor.CONSUME_STOPWATCH_KEY);
119
+ if (!attr) {
120
+ break;
121
+ }
122
+ const message = messages[0];
123
+ if (!message) {
124
+ break;
125
+ }
126
+ const cost = Date.now() - attr.get();
127
+ const attributes = {
128
+ [MetricLabels_1.MetricLabels.TOPIC]: message.topic,
129
+ [MetricLabels_1.MetricLabels.CLIENT_ID]: this.clientId,
130
+ [MetricLabels_1.MetricLabels.CONSUMER_GROUP]: consumerGroup,
131
+ [MetricLabels_1.MetricLabels.INVOCATION_STATUS]: invocationStatus.name,
132
+ };
133
+ this.meterManager.record(HistogramEnum_1.HistogramEnum.PROCESS_TIME, attributes, cost);
134
+ break;
135
+ }
136
+ default:
137
+ break;
138
+ }
139
+ }
140
+ #consumerAttributes(topic, consumerGroup) {
141
+ return {
142
+ [MetricLabels_1.MetricLabels.TOPIC]: topic,
143
+ [MetricLabels_1.MetricLabels.CLIENT_ID]: this.clientId,
144
+ [MetricLabels_1.MetricLabels.CONSUMER_GROUP]: consumerGroup,
145
+ };
146
+ }
147
+ }
148
+ exports.MessageMeterInterceptor = MessageMeterInterceptor;
149
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTWVzc2FnZU1ldGVySW50ZXJjZXB0b3IuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvaG9vay9NZXNzYWdlTWV0ZXJJbnRlcmNlcHRvci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7Ozs7Ozs7Ozs7Ozs7OztHQWVHOzs7QUFHSCx5QkFBd0k7QUFFeEksMERBQXVEO0FBQ3ZELGtFQUErRDtBQUMvRCw0REFBeUQ7QUFjekQ7Ozs7Ozs7O0dBUUc7QUFDSCxNQUFhLHVCQUF1QjtJQUtmO0lBQ0E7SUFDQTtJQU5uQixNQUFNLENBQVUsa0JBQWtCLEdBQUcsZUFBWSxDQUFDLE1BQU0sQ0FBUyxnQkFBZ0IsQ0FBQyxDQUFDO0lBQ25GLE1BQU0sQ0FBVSxxQkFBcUIsR0FBRyxlQUFZLENBQUMsTUFBTSxDQUFTLG1CQUFtQixDQUFDLENBQUM7SUFFekYsWUFDbUIsWUFBZ0MsRUFDaEMsUUFBZ0IsRUFDaEIsZ0JBQTBDO1FBRjFDLGlCQUFZLEdBQVosWUFBWSxDQUFvQjtRQUNoQyxhQUFRLEdBQVIsUUFBUSxDQUFRO1FBQ2hCLHFCQUFnQixHQUFoQixnQkFBZ0IsQ0FBMEI7SUFFN0QsQ0FBQztJQUVELFFBQVEsQ0FBQyxPQUFrQyxFQUFFLFFBQTBCO1FBQ3JFLElBQUksQ0FBQyxJQUFJLENBQUMsWUFBWSxDQUFDLFNBQVMsRUFBRSxFQUFFLENBQUM7WUFDbkMsT0FBTztRQUNULENBQUM7UUFDRCxRQUFRLE9BQU8sQ0FBQyxvQkF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sQ0FBQyw2QkFBYSxDQUFDLFlBQVksRUFBRSxVQUFVLEVBQUUsSUFBSSxDQUFDLENBQUM7Z0JBQ3ZFLE1BQU07WUFDUixDQUFDO1lBQ0Q7Z0JBQ0UsTUFBTTtRQUNWLENBQUM7SUFDSCxDQUFDO0lBRUQsbUJBQW1CLENBQUMsS0FBYSxFQUFFLGFBQXFCO1FBQ3RELE9BQU87WUFDTCxDQUFDLDJCQUFZLENBQUMsS0FBSyxDQUFDLEVBQUUsS0FBSztZQUMzQixDQUFDLDJCQUFZLENBQUMsU0FBUyxDQUFDLEVBQUUsSUFBSSxDQUFDLFFBQVE7WUFDdkMsQ0FBQywyQkFBWSxDQUFDLGNBQWMsQ0FBQyxFQUFFLGFBQWE7U0FDN0MsQ0FBQztJQUNKLENBQUM7O0FBbkhILDBEQW9IQyJ9
@@ -0,0 +1,26 @@
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
+ export * from './Attribute';
18
+ export * from './AttributeKey';
19
+ export * from './CompositedMessageInterceptor';
20
+ export * from './InflightRequestCountInterceptor';
21
+ export * from './MessageHookPoints';
22
+ export * from './MessageHookPointsStatus';
23
+ export * from './MessageInterceptor';
24
+ export * from './MessageInterceptorContext';
25
+ export * from './MessageInterceptorContextImpl';
26
+ export * from './MessageMeterInterceptor';
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ /**
3
+ * Licensed to the Apache Software Foundation (ASF) under one or more
4
+ * contributor license agreements. See the NOTICE file distributed with
5
+ * this work for additional information regarding copyright ownership.
6
+ * The ASF licenses this file to You under the Apache License, Version 2.0
7
+ * (the "License"); you may not use this file except in compliance with
8
+ * the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ var desc = Object.getOwnPropertyDescriptor(m, k);
21
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
22
+ desc = { enumerable: true, get: function() { return m[k]; } };
23
+ }
24
+ Object.defineProperty(o, k2, desc);
25
+ }) : (function(o, m, k, k2) {
26
+ if (k2 === undefined) k2 = k;
27
+ o[k2] = m[k];
28
+ }));
29
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
30
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
31
+ };
32
+ Object.defineProperty(exports, "__esModule", { value: true });
33
+ __exportStar(require("./Attribute"), exports);
34
+ __exportStar(require("./AttributeKey"), exports);
35
+ __exportStar(require("./CompositedMessageInterceptor"), exports);
36
+ __exportStar(require("./InflightRequestCountInterceptor"), exports);
37
+ __exportStar(require("./MessageHookPoints"), exports);
38
+ __exportStar(require("./MessageHookPointsStatus"), exports);
39
+ __exportStar(require("./MessageInterceptor"), exports);
40
+ __exportStar(require("./MessageInterceptorContext"), exports);
41
+ __exportStar(require("./MessageInterceptorContextImpl"), exports);
42
+ __exportStar(require("./MessageMeterInterceptor"), exports);
43
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvaG9vay9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7Ozs7Ozs7Ozs7Ozs7OztHQWVHOzs7Ozs7Ozs7Ozs7Ozs7O0FBRUgsOENBQTRCO0FBQzVCLGlEQUErQjtBQUMvQixpRUFBK0M7QUFDL0Msb0VBQWtEO0FBQ2xELHNEQUFvQztBQUNwQyw0REFBMEM7QUFDMUMsdURBQXFDO0FBQ3JDLDhEQUE0QztBQUM1QyxrRUFBZ0Q7QUFDaEQsNERBQTBDIn0=
package/dist/index.d.ts CHANGED
@@ -16,6 +16,7 @@
16
16
  */
17
17
  export * from './consumer';
18
18
  export * from './exception';
19
+ export * from './hook';
19
20
  export * from './message';
20
21
  export * from './producer';
21
22
  export * from './retry';
package/dist/index.js CHANGED
@@ -32,9 +32,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
32
32
  Object.defineProperty(exports, "__esModule", { value: true });
33
33
  __exportStar(require("./consumer"), exports);
34
34
  __exportStar(require("./exception"), exports);
35
+ __exportStar(require("./hook"), exports);
35
36
  __exportStar(require("./message"), exports);
36
37
  __exportStar(require("./producer"), exports);
37
38
  __exportStar(require("./retry"), exports);
38
39
  __exportStar(require("./route"), exports);
39
40
  __exportStar(require("./client"), exports);
40
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBOzs7Ozs7Ozs7Ozs7Ozs7R0FlRzs7Ozs7Ozs7Ozs7Ozs7OztBQUVILDZDQUEyQjtBQUMzQiw4Q0FBNEI7QUFDNUIsNENBQTBCO0FBQzFCLDZDQUEyQjtBQUMzQiwwQ0FBd0I7QUFDeEIsMENBQXdCO0FBQ3hCLDJDQUF5QiJ9
41
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBOzs7Ozs7Ozs7Ozs7Ozs7R0FlRzs7Ozs7Ozs7Ozs7Ozs7OztBQUVILDZDQUEyQjtBQUMzQiw4Q0FBNEI7QUFDNUIseUNBQXVCO0FBQ3ZCLDRDQUEwQjtBQUMxQiw2Q0FBMkI7QUFDM0IsMENBQXdCO0FBQ3hCLDBDQUF3QjtBQUN4QiwyQ0FBeUIifQ==
@@ -0,0 +1,42 @@
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
+ import { Attributes, Meter } from '@opentelemetry/api';
18
+ import { MeterProvider as SdkMeterProvider } from '@opentelemetry/sdk-metrics';
19
+ import { Endpoints } from '../route';
20
+ import { HistogramEnum } from './HistogramEnum';
21
+ import { Metric } from './Metric';
22
+ /**
23
+ * Wraps an OpenTelemetry {@link Meter} and records the four RocketMQ histograms.
24
+ * When metrics are disabled it is a no-op instance, mirroring
25
+ * org.apache.rocketmq.client.java.metrics.ClientMeter.
26
+ */
27
+ export declare class ClientMeter {
28
+ readonly enabled: boolean;
29
+ private readonly meter?;
30
+ private readonly endpoints?;
31
+ private readonly provider?;
32
+ private readonly histogramMap;
33
+ constructor(meter: Meter | null, endpoints: Endpoints | null, provider: SdkMeterProvider | null);
34
+ static disabledInstance(): ClientMeter;
35
+ record(histogramEnum: HistogramEnum, attributes: Attributes, value: number): void;
36
+ shutdown(): Promise<void>;
37
+ /**
38
+ * Returns true if the supplied metric switch is already satisfied by this
39
+ * meter (so a rebuild is unnecessary), mirroring ClientMeter#satisfy.
40
+ */
41
+ satisfy(metric: Metric): boolean;
42
+ }
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ /**
3
+ * Licensed to the Apache Software Foundation (ASF) under one or more
4
+ * contributor license agreements. See the NOTICE file distributed with
5
+ * this work for additional information regarding copyright ownership.
6
+ * The ASF licenses this file to You under the Apache License, Version 2.0
7
+ * (the "License"); you may not use this file except in compliance with
8
+ * the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.ClientMeter = void 0;
20
+ /**
21
+ * Wraps an OpenTelemetry {@link Meter} and records the four RocketMQ histograms.
22
+ * When metrics are disabled it is a no-op instance, mirroring
23
+ * org.apache.rocketmq.client.java.metrics.ClientMeter.
24
+ */
25
+ class ClientMeter {
26
+ enabled;
27
+ meter;
28
+ endpoints;
29
+ provider;
30
+ histogramMap = new Map();
31
+ constructor(meter, endpoints, provider) {
32
+ this.enabled = meter != null && endpoints != null && provider != null;
33
+ this.meter = meter ?? undefined;
34
+ this.endpoints = endpoints ?? undefined;
35
+ this.provider = provider ?? undefined;
36
+ }
37
+ static disabledInstance() {
38
+ return new ClientMeter(null, null, null);
39
+ }
40
+ record(histogramEnum, attributes, value) {
41
+ if (!this.enabled || !this.meter) {
42
+ return;
43
+ }
44
+ let histogram = this.histogramMap.get(histogramEnum);
45
+ if (!histogram) {
46
+ histogram = this.meter.createHistogram(histogramEnum);
47
+ this.histogramMap.set(histogramEnum, histogram);
48
+ }
49
+ histogram.record(value, attributes);
50
+ }
51
+ async shutdown() {
52
+ if (!this.enabled || !this.provider) {
53
+ return;
54
+ }
55
+ try {
56
+ await this.provider.shutdown();
57
+ }
58
+ catch (t) {
59
+ // best-effort shutdown, ignore
60
+ }
61
+ }
62
+ /**
63
+ * Returns true if the supplied metric switch is already satisfied by this
64
+ * meter (so a rebuild is unnecessary), mirroring ClientMeter#satisfy.
65
+ */
66
+ satisfy(metric) {
67
+ if (this.enabled && metric.on && this.endpoints != null && metric.endpoints != null
68
+ && this.endpoints.equals(metric.endpoints)) {
69
+ return true;
70
+ }
71
+ return !this.enabled && !metric.on;
72
+ }
73
+ }
74
+ exports.ClientMeter = ClientMeter;
75
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ2xpZW50TWV0ZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbWV0cmljcy9DbGllbnRNZXRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7Ozs7Ozs7Ozs7Ozs7OztHQWVHOzs7QUFRSDs7OztHQUlHO0FBQ0gsTUFBYSxXQUFXO0lBQ2IsT0FBTyxDQUFVO0lBQ1QsS0FBSyxDQUFTO0lBQ2QsU0FBUyxDQUFhO0lBQ3RCLFFBQVEsQ0FBb0I7SUFDNUIsWUFBWSxHQUFHLElBQUksR0FBRyxFQUE0QixDQUFDO0lBRXBFLFlBQVksS0FBbUIsRUFBRSxTQUEyQixFQUFFLFFBQWlDO1FBQzdGLElBQUksQ0FBQyxPQUFPLEdBQUcsS0FBSyxJQUFJLElBQUksSUFBSSxTQUFTLElBQUksSUFBSSxJQUF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