rocketmq-client-nodejs 0.0.0 → 1.0.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.
- package/LICENSE +201 -0
- package/README.md +69 -1
- package/dist/client/BaseClient.d.ts +92 -0
- package/dist/client/BaseClient.js +308 -0
- package/dist/client/ClientId.d.ts +24 -0
- package/dist/client/ClientId.js +33 -0
- package/dist/client/Logger.d.ts +24 -0
- package/dist/client/Logger.js +34 -0
- package/dist/client/RpcClient.d.ts +47 -0
- package/dist/client/RpcClient.js +208 -0
- package/dist/client/RpcClientManager.d.ts +41 -0
- package/dist/client/RpcClientManager.js +139 -0
- package/dist/client/SessionCredentials.d.ts +21 -0
- package/dist/client/SessionCredentials.js +19 -0
- package/dist/client/Settings.d.ts +30 -0
- package/dist/client/Settings.js +38 -0
- package/dist/client/TelemetrySession.d.ts +27 -0
- package/dist/client/TelemetrySession.js +101 -0
- package/dist/client/UserAgent.d.ts +25 -0
- package/dist/client/UserAgent.js +47 -0
- package/dist/client/index.d.ts +26 -0
- package/dist/client/index.js +43 -0
- package/dist/consumer/Consumer.d.ts +32 -0
- package/dist/consumer/Consumer.js +96 -0
- package/dist/consumer/FilterExpression.d.ts +25 -0
- package/dist/consumer/FilterExpression.js +40 -0
- package/dist/consumer/SimpleConsumer.d.ts +47 -8
- package/dist/consumer/SimpleConsumer.js +105 -27
- package/dist/consumer/SimpleSubscriptionSettings.d.ts +28 -0
- package/dist/consumer/SimpleSubscriptionSettings.js +57 -0
- package/dist/consumer/SubscriptionLoadBalancer.d.ts +23 -0
- package/dist/consumer/SubscriptionLoadBalancer.js +46 -0
- package/dist/consumer/index.d.ts +21 -0
- package/dist/consumer/index.js +38 -0
- package/dist/exception/BadRequestException.d.ts +20 -0
- package/dist/exception/BadRequestException.js +28 -0
- package/dist/exception/ClientException.d.ts +20 -0
- package/dist/exception/ClientException.js +31 -0
- package/dist/exception/ForbiddenException.d.ts +20 -0
- package/dist/exception/ForbiddenException.js +28 -0
- package/dist/exception/InternalErrorException.d.ts +20 -0
- package/dist/exception/InternalErrorException.js +28 -0
- package/dist/exception/NotFoundException.d.ts +20 -0
- package/dist/exception/NotFoundException.js +28 -0
- package/dist/exception/PayloadTooLargeException.d.ts +20 -0
- package/dist/exception/PayloadTooLargeException.js +28 -0
- package/dist/exception/PaymentRequiredException.d.ts +20 -0
- package/dist/exception/PaymentRequiredException.js +28 -0
- package/dist/exception/ProxyTimeoutException.d.ts +20 -0
- package/dist/exception/ProxyTimeoutException.js +28 -0
- package/dist/exception/RequestHeaderFieldsTooLargeException.d.ts +20 -0
- package/dist/exception/RequestHeaderFieldsTooLargeException.js +28 -0
- package/dist/exception/StatusChecker.d.ts +20 -0
- package/dist/exception/StatusChecker.js +98 -0
- package/dist/exception/TooManyRequestsException.d.ts +20 -0
- package/dist/exception/TooManyRequestsException.js +28 -0
- package/dist/exception/UnauthorizedException.d.ts +20 -0
- package/dist/exception/UnauthorizedException.js +28 -0
- package/dist/exception/UnsupportedException.d.ts +20 -0
- package/dist/exception/UnsupportedException.js +28 -0
- package/dist/exception/index.d.ts +29 -0
- package/dist/exception/index.js +46 -0
- package/dist/index.d.ts +22 -3
- package/dist/index.js +23 -4
- package/dist/message/Message.d.ts +37 -0
- package/dist/message/Message.js +43 -0
- package/dist/message/MessageId.d.ts +59 -0
- package/dist/message/MessageId.js +123 -0
- package/dist/message/MessageView.d.ts +39 -0
- package/dist/message/MessageView.js +90 -0
- package/dist/message/PublishingMessage.d.ts +30 -0
- package/dist/message/PublishingMessage.js +98 -0
- package/dist/message/index.d.ts +20 -0
- package/dist/message/index.js +37 -0
- package/dist/producer/Producer.d.ts +42 -0
- package/dist/producer/Producer.js +242 -1
- package/dist/producer/PublishingLoadBalancer.d.ts +24 -0
- package/dist/producer/PublishingLoadBalancer.js +82 -0
- package/dist/producer/PublishingSettings.d.ts +28 -0
- package/dist/producer/PublishingSettings.js +70 -0
- package/dist/producer/SendReceipt.d.ts +28 -0
- package/dist/producer/SendReceipt.js +57 -0
- package/dist/producer/Transaction.d.ts +28 -0
- package/dist/producer/Transaction.js +64 -0
- package/dist/producer/TransactionChecker.d.ts +21 -0
- package/dist/producer/TransactionChecker.js +19 -0
- package/dist/producer/index.d.ts +21 -0
- package/dist/producer/index.js +39 -0
- package/dist/retry/ExponentialBackoffRetryPolicy.d.ts +27 -0
- package/dist/retry/ExponentialBackoffRetryPolicy.js +67 -0
- package/dist/retry/RetryPolicy.d.ts +46 -0
- package/dist/retry/RetryPolicy.js +19 -0
- package/dist/retry/index.d.ts +18 -0
- package/dist/retry/index.js +35 -0
- package/dist/route/Broker.d.ts +25 -0
- package/dist/route/Broker.js +40 -0
- package/dist/route/Endpoints.d.ts +30 -0
- package/dist/route/Endpoints.js +71 -0
- package/dist/route/MessageQueue.d.ts +27 -0
- package/dist/route/MessageQueue.js +47 -0
- package/dist/route/TopicRouteData.d.ts +24 -0
- package/dist/route/TopicRouteData.js +37 -0
- package/dist/route/index.d.ts +20 -0
- package/dist/route/index.js +37 -0
- package/dist/util/index.d.ts +36 -0
- package/dist/util/index.js +88 -0
- package/package.json +12 -5
- package/src/client/BaseClient.ts +384 -0
- package/src/client/ClientId.ts +31 -0
- package/src/client/Logger.ts +35 -0
- package/src/client/RpcClient.ts +245 -0
- package/src/client/RpcClientManager.ts +173 -0
- package/src/client/SessionCredentials.ts +22 -0
- package/src/client/Settings.ts +45 -0
- package/src/client/TelemetrySession.ts +118 -0
- package/src/client/UserAgent.ts +45 -0
- package/src/client/index.ts +27 -0
- package/src/consumer/Consumer.ts +111 -0
- package/src/consumer/FilterExpression.ts +42 -0
- package/src/consumer/SimpleConsumer.ts +133 -20
- package/src/consumer/SimpleSubscriptionSettings.ts +65 -0
- package/src/consumer/SubscriptionLoadBalancer.ts +47 -0
- package/src/consumer/index.ts +22 -0
- package/src/exception/BadRequestException.ts +25 -0
- package/src/exception/ClientException.ts +29 -0
- package/src/exception/ForbiddenException.ts +25 -0
- package/src/exception/InternalErrorException.ts +25 -0
- package/src/exception/NotFoundException.ts +25 -0
- package/src/exception/PayloadTooLargeException.ts +25 -0
- package/src/exception/PaymentRequiredException.ts +25 -0
- package/src/exception/ProxyTimeoutException.ts +25 -0
- package/src/exception/RequestHeaderFieldsTooLargeException.ts +25 -0
- package/src/exception/StatusChecker.ts +94 -0
- package/src/exception/TooManyRequestsException.ts +25 -0
- package/src/exception/UnauthorizedException.ts +25 -0
- package/src/exception/UnsupportedException.ts +25 -0
- package/src/exception/index.ts +30 -0
- package/src/index.ts +23 -3
- package/src/message/Message.ts +51 -0
- package/src/message/MessageId.ts +123 -0
- package/src/message/MessageView.ts +94 -0
- package/src/message/PublishingMessage.ts +102 -0
- package/src/message/index.ts +21 -0
- package/src/producer/Producer.ts +291 -0
- package/src/producer/PublishingLoadBalancer.ts +85 -0
- package/src/producer/PublishingSettings.ts +79 -0
- package/src/producer/SendReceipt.ts +60 -0
- package/src/producer/Transaction.ts +70 -0
- package/src/producer/TransactionChecker.ts +23 -0
- package/src/producer/index.ts +23 -0
- package/src/retry/ExponentialBackoffRetryPolicy.ts +76 -0
- package/src/retry/RetryPolicy.ts +51 -0
- package/src/retry/index.ts +19 -0
- package/src/route/Broker.ts +39 -0
- package/src/route/Endpoints.ts +70 -0
- package/src/route/MessageQueue.ts +49 -0
- package/src/route/TopicRouteData.ts +38 -0
- package/src/route/index.ts +21 -0
- package/src/util/index.ts +83 -0
- package/dist/grpc/MessagingServiceClient.d.ts +0 -9
- package/dist/grpc/MessagingServiceClient.js +0 -13
- package/dist/model/SessionCredentials.d.ts +0 -5
- package/dist/model/SessionCredentials.js +0 -3
- package/src/grpc/MessagingServiceClient.ts +0 -17
- package/src/model/SessionCredentials.ts +0 -5
|
@@ -0,0 +1,24 @@
|
|
|
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 { MessageQueue as MessageQueuePB } from '../../proto/apache/rocketmq/v2/definition_pb';
|
|
18
|
+
import { Endpoints } from './Endpoints';
|
|
19
|
+
import { MessageQueue } from './MessageQueue';
|
|
20
|
+
export declare class TopicRouteData {
|
|
21
|
+
readonly messageQueues: MessageQueue[];
|
|
22
|
+
constructor(messageQueues: MessageQueuePB[]);
|
|
23
|
+
getTotalEndpoints(): Endpoints[];
|
|
24
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
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.TopicRouteData = void 0;
|
|
20
|
+
const MessageQueue_1 = require("./MessageQueue");
|
|
21
|
+
class TopicRouteData {
|
|
22
|
+
messageQueues = [];
|
|
23
|
+
constructor(messageQueues) {
|
|
24
|
+
for (const mq of messageQueues) {
|
|
25
|
+
this.messageQueues.push(new MessageQueue_1.MessageQueue(mq));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
getTotalEndpoints() {
|
|
29
|
+
const endpointsMap = new Map();
|
|
30
|
+
for (const mq of this.messageQueues) {
|
|
31
|
+
endpointsMap.set(mq.broker.endpoints.facade, mq.broker.endpoints);
|
|
32
|
+
}
|
|
33
|
+
return Array.from(endpointsMap.values());
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.TopicRouteData = TopicRouteData;
|
|
37
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiVG9waWNSb3V0ZURhdGEuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvcm91dGUvVG9waWNSb3V0ZURhdGEudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBOzs7Ozs7Ozs7Ozs7Ozs7R0FlRzs7O0FBSUgsaURBQThDO0FBRTlDLE1BQWEsY0FBYztJQUNoQixhQUFhLEdBQW1CLEVBQUUsQ0FBQztJQUU1QyxZQUFZLGFBQStCO1FBQ3pDLEtBQUssTUFBTSxFQUFFLElBQUksYUFBYSxFQUFFLENBQUM7WUFDL0IsSUFBSSxDQUFDLGFBQWEsQ0FBQyxJQUFJLENBQUMsSUFBSSwyQkFBWSxDQUFDLEVBQUUsQ0FBQyxDQUFDLENBQUM7UUFDaEQsQ0FBQztJQUNILENBQUM7SUFFRCxpQkFBaUI7UUFDZixNQUFNLFlBQVksR0FBRyxJQUFJLEdBQUcsRUFBcUIsQ0FBQztRQUNsRCxLQUFLLE1BQU0sRUFBRSxJQUFJLElBQUksQ0FBQyxhQUFhLEVBQUUsQ0FBQztZQUNwQyxZQUFZLENBQUMsR0FBRyxDQUFDLEVBQUUsQ0FBQyxNQUFNLENBQUMsU0FBUyxDQUFDLE1BQU0sRUFBRSxFQUFFLENBQUMsTUFBTSxDQUFDLFNBQVMsQ0FBQyxDQUFDO1FBQ3BFLENBQUM7UUFDRCxPQUFPLEtBQUssQ0FBQyxJQUFJLENBQUMsWUFBWSxDQUFDLE1BQU0sRUFBRSxDQUFDLENBQUM7SUFDM0MsQ0FBQztDQUNGO0FBaEJELHdDQWdCQyJ9
|
|
@@ -0,0 +1,20 @@
|
|
|
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 './Broker';
|
|
18
|
+
export * from './Endpoints';
|
|
19
|
+
export * from './MessageQueue';
|
|
20
|
+
export * from './TopicRouteData';
|
|
@@ -0,0 +1,37 @@
|
|
|
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("./Broker"), exports);
|
|
34
|
+
__exportStar(require("./Endpoints"), exports);
|
|
35
|
+
__exportStar(require("./MessageQueue"), exports);
|
|
36
|
+
__exportStar(require("./TopicRouteData"), exports);
|
|
37
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvcm91dGUvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBOzs7Ozs7Ozs7Ozs7Ozs7R0FlRzs7Ozs7Ozs7Ozs7Ozs7OztBQUVILDJDQUF5QjtBQUN6Qiw4Q0FBNEI7QUFDNUIsaURBQStCO0FBQy9CLG1EQUFpQyJ9
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
/// <reference types="node" />
|
|
18
|
+
import { Duration } from 'google-protobuf/google/protobuf/duration_pb';
|
|
19
|
+
import { Resource } from '../../proto/apache/rocketmq/v2/definition_pb';
|
|
20
|
+
export declare const MASTER_BROKER_ID = 0;
|
|
21
|
+
export declare function getTimestamp(): {
|
|
22
|
+
seconds: number;
|
|
23
|
+
nanos: number;
|
|
24
|
+
timestamp: number;
|
|
25
|
+
};
|
|
26
|
+
export declare function getRequestDateTime(): string;
|
|
27
|
+
export declare function sign(accessSecret: string, dateTime: string): string;
|
|
28
|
+
export declare function createDuration(ms: number): Duration;
|
|
29
|
+
export declare function createResource(name: string): Resource;
|
|
30
|
+
export declare function crc32CheckSum(bytes: Buffer): string;
|
|
31
|
+
export declare function md5CheckSum(bytes: Uint8Array): string;
|
|
32
|
+
export declare function sha1CheckSum(bytes: Uint8Array): string;
|
|
33
|
+
/**
|
|
34
|
+
* Java: Hashing.sipHash24().hashBytes(messageGroup.getBytes(StandardCharsets.UTF_8)).asLong()
|
|
35
|
+
*/
|
|
36
|
+
export declare function calculateStringSipHash24(value: string): bigint;
|
|
@@ -0,0 +1,88 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
19
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.calculateStringSipHash24 = exports.sha1CheckSum = exports.md5CheckSum = exports.crc32CheckSum = exports.createResource = exports.createDuration = exports.sign = exports.getRequestDateTime = exports.getTimestamp = exports.MASTER_BROKER_ID = void 0;
|
|
23
|
+
const node_perf_hooks_1 = require("node:perf_hooks");
|
|
24
|
+
const node_crypto_1 = require("node:crypto");
|
|
25
|
+
const duration_pb_1 = require("google-protobuf/google/protobuf/duration_pb");
|
|
26
|
+
const crc32_1 = require("@node-rs/crc32");
|
|
27
|
+
const siphash24_1 = __importDefault(require("siphash24"));
|
|
28
|
+
const definition_pb_1 = require("../../proto/apache/rocketmq/v2/definition_pb");
|
|
29
|
+
exports.MASTER_BROKER_ID = 0;
|
|
30
|
+
function getTimestamp() {
|
|
31
|
+
const timestamp = node_perf_hooks_1.performance.timeOrigin + node_perf_hooks_1.performance.now();
|
|
32
|
+
const seconds = Math.floor(timestamp / 1000);
|
|
33
|
+
const nanos = Math.floor((timestamp % 1000) * 1e6);
|
|
34
|
+
return { seconds, nanos, timestamp };
|
|
35
|
+
}
|
|
36
|
+
exports.getTimestamp = getTimestamp;
|
|
37
|
+
// DATE_TIME_FORMAT = "yyyyMMdd'T'HHmmss'Z'"
|
|
38
|
+
function getRequestDateTime() {
|
|
39
|
+
// 2023-09-13T06:30:59.399Z => 20230913T063059Z
|
|
40
|
+
const now = new Date().toISOString().split('.')[0].replace(/[\-\:]/g, '');
|
|
41
|
+
return `${now}Z`;
|
|
42
|
+
}
|
|
43
|
+
exports.getRequestDateTime = getRequestDateTime;
|
|
44
|
+
function sign(accessSecret, dateTime) {
|
|
45
|
+
const hmacSha1 = (0, node_crypto_1.createHmac)('sha1', accessSecret);
|
|
46
|
+
hmacSha1.update(dateTime);
|
|
47
|
+
return hmacSha1.digest('hex').toUpperCase();
|
|
48
|
+
}
|
|
49
|
+
exports.sign = sign;
|
|
50
|
+
function createDuration(ms) {
|
|
51
|
+
const nanos = ms % 1000 * 1000000;
|
|
52
|
+
return new duration_pb_1.Duration()
|
|
53
|
+
.setSeconds(ms / 1000)
|
|
54
|
+
.setNanos(nanos);
|
|
55
|
+
}
|
|
56
|
+
exports.createDuration = createDuration;
|
|
57
|
+
function createResource(name) {
|
|
58
|
+
return new definition_pb_1.Resource().setName(name);
|
|
59
|
+
}
|
|
60
|
+
exports.createResource = createResource;
|
|
61
|
+
function crc32CheckSum(bytes) {
|
|
62
|
+
return `${(0, crc32_1.crc32)(bytes)}`;
|
|
63
|
+
}
|
|
64
|
+
exports.crc32CheckSum = crc32CheckSum;
|
|
65
|
+
function md5CheckSum(bytes) {
|
|
66
|
+
return (0, node_crypto_1.createHash)('md5').update(bytes).digest('hex')
|
|
67
|
+
.toUpperCase();
|
|
68
|
+
}
|
|
69
|
+
exports.md5CheckSum = md5CheckSum;
|
|
70
|
+
function sha1CheckSum(bytes) {
|
|
71
|
+
return (0, node_crypto_1.createHash)('sha1').update(bytes).digest('hex')
|
|
72
|
+
.toUpperCase();
|
|
73
|
+
}
|
|
74
|
+
exports.sha1CheckSum = sha1CheckSum;
|
|
75
|
+
// k0: 0x0706050403020100L, k1: 0x0f0e0d0c0b0a0908L
|
|
76
|
+
const SIP_HASH_24_KEY = Buffer.from([
|
|
77
|
+
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
|
78
|
+
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
|
79
|
+
]);
|
|
80
|
+
/**
|
|
81
|
+
* Java: Hashing.sipHash24().hashBytes(messageGroup.getBytes(StandardCharsets.UTF_8)).asLong()
|
|
82
|
+
*/
|
|
83
|
+
function calculateStringSipHash24(value) {
|
|
84
|
+
const hash = (0, siphash24_1.default)(Buffer.from(value), SIP_HASH_24_KEY);
|
|
85
|
+
return Buffer.from(hash).readBigUInt64BE();
|
|
86
|
+
}
|
|
87
|
+
exports.calculateStringSipHash24 = calculateStringSipHash24;
|
|
88
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdXRpbC9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7Ozs7Ozs7Ozs7Ozs7OztHQWVHOzs7Ozs7QUFFSCxxREFBOEM7QUFDOUMsNkNBQXFEO0FBQ3JELDZFQUF1RTtBQUN2RSwwQ0FBdUM7QUFDdkMsMERBQWtDO0FBQ2xDLGdGQUF3RTtBQUUzRCxRQUFBLGdCQUFnQixHQUFHLENBQUMsQ0FBQztBQUVsQyxTQUFnQixZQUFZO0lBQzFCLE1BQU0sU0FBUyxHQUFHLDZCQUFXLENBQUMsVUFBVSxHQUFHLDZCQUFXLENBQUMsR0FBRyxFQUFFLENBQUM7SUFDN0QsTUFBTSxPQUFPLEdBQUcsSUFBSSxDQUFDLEtBQUssQ0FBQyxTQUFTLEdBQUcsSUFBSSxDQUFDLENBQUM7SUFDN0MsTUFBTSxLQUFLLEdBQUcsSUFBSSxDQUFDLEtBQUssQ0FBQyxDQUFDLFNBQVMsR0FBRyxJQUFJLENBQUMsR0FBRyxHQUFHLENBQUMsQ0FBQztJQUNuRCxPQUFPLEVBQUUsT0FBTyxFQUFFLEtBQUssRUFBRSxTQUFTLEVBQUUsQ0FBQztBQUN2QyxDQUFDO0FBTEQsb0NBS0M7QUFFRCw0Q0FBNEM7QUFDNUMsU0FBZ0Isa0JBQWtCO0lBQ2hDLCtDQUErQztJQUMvQyxNQUFNLEdBQUcsR0FBRyxJQUFJLElBQUksRUFBRSxDQUFDLFdBQVcsRUFBRSxDQUFDLEtBQUssQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxPQUFPLENBQUMsU0FBUyxFQUFFLEVBQUUsQ0FBQyxDQUFDO0lBQzFFLE9BQU8sR0FBRyxHQUFHLEdBQUcsQ0FBQztBQUNuQixDQUFDO0FBSkQsZ0RBSUM7QUFFRCxTQUFnQixJQUFJLENBQUMsWUFBb0IsRUFBRSxRQUFnQjtJQUN6RCxNQUFNLFFBQVEsR0FBRyxJQUFBLHdCQUFVLEVBQUMsTUFBTSxFQUFFLFlBQVksQ0FBQyxDQUFDO0lBQ2xELFFBQVEsQ0FBQyxNQUFNLENBQUMsUUFBUSxDQUFDLENBQUM7SUFDMUIsT0FBTyxRQUFRLENBQUMsTUFBTSxDQUFDLEtBQUssQ0FBQyxDQUFDLFdBQVcsRUFBRSxDQUFDO0FBQzlDLENBQUM7QUFKRCxvQkFJQztBQUVELFNBQWdCLGNBQWMsQ0FBQyxFQUFVO0lBQ3ZDLE1BQU0sS0FBSyxHQUFHLEVBQUUsR0FBRyxJQUFJLEdBQUcsT0FBTyxDQUFDO0lBQ2xDLE9BQU8sSUFBSSxzQkFBUSxFQUFFO1NBQ2xCLFVBQVUsQ0FBQyxFQUFFLEdBQUcsSUFBSSxDQUFDO1NBQ3JCLFFBQVEsQ0FBQyxLQUFLLENBQUMsQ0FBQztBQUNyQixDQUFDO0FBTEQsd0NBS0M7QUFFRCxTQUFnQixjQUFjLENBQUMsSUFBWTtJQUN6QyxPQUFPLElBQUksd0JBQVEsRUFBRSxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FBQztBQUN0QyxDQUFDO0FBRkQsd0NBRUM7QUFFRCxTQUFnQixhQUFhLENBQUMsS0FBYTtJQUN6QyxPQUFPLEdBQUcsSUFBQSxhQUFLLEVBQUMsS0FBSyxDQUFDLEVBQUUsQ0FBQztBQUMzQixDQUFDO0FBRkQsc0NBRUM7QUFFRCxTQUFnQixXQUFXLENBQUMsS0FBaUI7SUFDM0MsT0FBTyxJQUFBLHdCQUFVLEVBQUMsS0FBSyxDQUFDLENBQUMsTUFBTSxDQUFDLEtBQUssQ0FBQyxDQUFDLE1BQU0sQ0FBQyxLQUFLLENBQUM7U0FDakQsV0FBVyxFQUFFLENBQUM7QUFDbkIsQ0FBQztBQUhELGtDQUdDO0FBRUQsU0FBZ0IsWUFBWSxDQUFDLEtBQWlCO0lBQzVDLE9BQU8sSUFBQSx3QkFBVSxFQUFDLE1BQU0sQ0FBQyxDQUFDLE1BQU0sQ0FBQyxLQUFLLENBQUMsQ0FBQyxNQUFNLENBQUMsS0FBSyxDQUFDO1NBQ2xELFdBQVcsRUFBRSxDQUFDO0FBQ25CLENBQUM7QUFIRCxvQ0FHQztBQUVELG1EQUFtRDtBQUNuRCxNQUFNLGVBQWUsR0FBRyxNQUFNLENBQUMsSUFBSSxDQUFDO0lBQ2xDLElBQUksRUFBRSxJQUFJLEVBQUUsSUFBSSxFQUFFLElBQUksRUFBRSxJQUFJLEVBQUUsSUFBSSxFQUFFLElBQUksRUFBRSxJQUFJO0lBQzlDLElBQUksRUFBRSxJQUFJLEVBQUUsSUFBSSxFQUFFLElBQUksRUFBRSxJQUFJLEVBQUUsSUFBSSxFQUFFLElBQUksRUFBRSxJQUFJO0NBQy9DLENBQUMsQ0FBQztBQUNIOztHQUVHO0FBQ0gsU0FBZ0Isd0JBQXdCLENBQUMsS0FBYTtJQUNwRCxNQUFNLElBQUksR0FBRyxJQUFBLG1CQUFTLEVBQUMsTUFBTSxDQUFDLElBQUksQ0FBQyxLQUFLLENBQUMsRUFBRSxlQUFlLENBQUMsQ0FBQztJQUM1RCxPQUFPLE1BQU0sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLENBQUMsZUFBZSxFQUFFLENBQUM7QUFDN0MsQ0FBQztBQUhELDREQUdDIn0=
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rocketmq-client-nodejs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "RocketMQ Node.js Client",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -12,12 +12,15 @@
|
|
|
12
12
|
"scripts": {
|
|
13
13
|
"init": "npm run build:grpc",
|
|
14
14
|
"test": "egg-bin test",
|
|
15
|
-
"
|
|
15
|
+
"cov": "egg-bin cov",
|
|
16
|
+
"lint": "eslint src test",
|
|
16
17
|
"build:grpc": "scripts/build-grpc.sh",
|
|
17
18
|
"clean": "rm -rf dist *.d.ts",
|
|
18
|
-
"tsc": "tsc -p tsconfig.json",
|
|
19
|
+
"tsc": "tsc -p tsconfig.prod.json",
|
|
19
20
|
"build": "npm run clean && npm run build:grpc && npm run tsc",
|
|
20
|
-
"
|
|
21
|
+
"start-rocketmq": "sh test/start-rocketmq.sh",
|
|
22
|
+
"ci": "npm run lint && npm run build && npm run cov",
|
|
23
|
+
"prepublishOnly": "npm run build"
|
|
21
24
|
},
|
|
22
25
|
"repository": {
|
|
23
26
|
"type": "git",
|
|
@@ -46,7 +49,11 @@
|
|
|
46
49
|
},
|
|
47
50
|
"dependencies": {
|
|
48
51
|
"@grpc/grpc-js": "^1.9.1",
|
|
49
|
-
"
|
|
52
|
+
"@node-rs/crc32": "^1.7.2",
|
|
53
|
+
"address": "^1.2.2",
|
|
54
|
+
"egg-logger": "^3.4.0",
|
|
55
|
+
"google-protobuf": "^3.21.2",
|
|
56
|
+
"siphash24": "^1.3.1"
|
|
50
57
|
},
|
|
51
58
|
"engines": {
|
|
52
59
|
"node": ">=16.19.0"
|
|
@@ -0,0 +1,384 @@
|
|
|
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 { debuglog } from 'node:util';
|
|
19
|
+
import { randomUUID } from 'node:crypto';
|
|
20
|
+
import { Metadata } from '@grpc/grpc-js';
|
|
21
|
+
import {
|
|
22
|
+
Settings as SettingsPB,
|
|
23
|
+
Status,
|
|
24
|
+
ClientType,
|
|
25
|
+
Code,
|
|
26
|
+
} from '../../proto/apache/rocketmq/v2/definition_pb';
|
|
27
|
+
import {
|
|
28
|
+
QueryRouteRequest,
|
|
29
|
+
RecoverOrphanedTransactionCommand,
|
|
30
|
+
VerifyMessageCommand,
|
|
31
|
+
PrintThreadStackTraceCommand,
|
|
32
|
+
TelemetryCommand,
|
|
33
|
+
ThreadStackTrace,
|
|
34
|
+
HeartbeatRequest,
|
|
35
|
+
NotifyClientTerminationRequest,
|
|
36
|
+
} from '../../proto/apache/rocketmq/v2/service_pb';
|
|
37
|
+
import { createResource, getRequestDateTime, sign } from '../util';
|
|
38
|
+
import { TopicRouteData, Endpoints } from '../route';
|
|
39
|
+
import { ClientException, StatusChecker } from '../exception';
|
|
40
|
+
import { Settings } from './Settings';
|
|
41
|
+
import { UserAgent } from './UserAgent';
|
|
42
|
+
import { ILogger, getDefaultLogger } from './Logger';
|
|
43
|
+
import { SessionCredentials } from './SessionCredentials';
|
|
44
|
+
import { RpcClientManager } from './RpcClientManager';
|
|
45
|
+
import { TelemetrySession } from './TelemetrySession';
|
|
46
|
+
import { ClientId } from './ClientId';
|
|
47
|
+
|
|
48
|
+
const debug = debuglog('rocketmq-client-nodejs:client:BaseClient');
|
|
49
|
+
|
|
50
|
+
export interface BaseClientOptions {
|
|
51
|
+
sslEnabled?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* rocketmq cluster endpoints, e.g.:
|
|
54
|
+
* - 127.0.0.1:8081;127.0.0.1:8082
|
|
55
|
+
* - 127.0.0.1:8081
|
|
56
|
+
* - example.com
|
|
57
|
+
* - example.com:8443
|
|
58
|
+
*/
|
|
59
|
+
endpoints: string;
|
|
60
|
+
sessionCredentials?: SessionCredentials;
|
|
61
|
+
requestTimeout?: number;
|
|
62
|
+
logger?: ILogger;
|
|
63
|
+
topics?: string[];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* RocketMQ Base Client, Consumer and Producer should extends this class
|
|
68
|
+
*
|
|
69
|
+
* it handle:
|
|
70
|
+
* - RpcClient lifecycle, e.g: cleanup the idle clients
|
|
71
|
+
* - startup flow
|
|
72
|
+
* - periodic Task
|
|
73
|
+
*/
|
|
74
|
+
export abstract class BaseClient {
|
|
75
|
+
readonly clientId = ClientId.create();
|
|
76
|
+
readonly clientType = ClientType.CLIENT_TYPE_UNSPECIFIED;
|
|
77
|
+
readonly sslEnabled: boolean;
|
|
78
|
+
readonly #sessionCredentials?: SessionCredentials;
|
|
79
|
+
protected readonly endpoints: Endpoints;
|
|
80
|
+
protected readonly isolated = new Map<string, Endpoints>();
|
|
81
|
+
protected readonly requestTimeout: number;
|
|
82
|
+
protected readonly topics = new Set<string>();
|
|
83
|
+
protected readonly topicRouteCache = new Map<string, TopicRouteData>();
|
|
84
|
+
protected readonly logger: ILogger;
|
|
85
|
+
protected readonly rpcClientManager: RpcClientManager;
|
|
86
|
+
readonly #telemetrySessions = new Map<string, TelemetrySession>();
|
|
87
|
+
#startupResolve?: () => void;
|
|
88
|
+
#startupReject?: (err: Error) => void;
|
|
89
|
+
#timers: NodeJS.Timeout[] = [];
|
|
90
|
+
|
|
91
|
+
constructor(options: BaseClientOptions) {
|
|
92
|
+
this.logger = options.logger ?? getDefaultLogger();
|
|
93
|
+
this.sslEnabled = options.sslEnabled === true;
|
|
94
|
+
this.endpoints = new Endpoints(options.endpoints);
|
|
95
|
+
this.#sessionCredentials = options.sessionCredentials;
|
|
96
|
+
// https://rocketmq.apache.org/docs/introduction/03limits/
|
|
97
|
+
// Default request timeout is 3000ms
|
|
98
|
+
this.requestTimeout = options.requestTimeout ?? 3000;
|
|
99
|
+
this.rpcClientManager = new RpcClientManager(this, this.logger);
|
|
100
|
+
if (options.topics) {
|
|
101
|
+
for (const topic of options.topics) {
|
|
102
|
+
this.topics.add(topic);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Startup flow
|
|
109
|
+
* https://github.com/apache/rocketmq-clients/blob/master/docs/workflow.md#startup
|
|
110
|
+
*/
|
|
111
|
+
async startup() {
|
|
112
|
+
this.logger.info('Begin to startup the rocketmq client, clientId=%s', this.clientId);
|
|
113
|
+
try {
|
|
114
|
+
await this.#startup();
|
|
115
|
+
} catch (e) {
|
|
116
|
+
const err = new Error(`Startup the rocketmq client failed, clientId=${this.clientId}, error=${e}`);
|
|
117
|
+
this.logger.error(err);
|
|
118
|
+
err.cause = e;
|
|
119
|
+
throw err;
|
|
120
|
+
}
|
|
121
|
+
this.logger.info('Startup the rocketmq client successfully, clientId=%s', this.clientId);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async #startup() {
|
|
125
|
+
// fetch topic route
|
|
126
|
+
await this.updateRoutes();
|
|
127
|
+
// update topic route every 30s
|
|
128
|
+
this.#timers.push(setInterval(async () => {
|
|
129
|
+
this.updateRoutes();
|
|
130
|
+
}, 30000));
|
|
131
|
+
|
|
132
|
+
// sync settings every 5m
|
|
133
|
+
this.#timers.push(setInterval(async () => {
|
|
134
|
+
this.#syncSettings();
|
|
135
|
+
}, 5 * 60000));
|
|
136
|
+
|
|
137
|
+
// heartbeat every 10s
|
|
138
|
+
this.#timers.push(setInterval(async () => {
|
|
139
|
+
this.#doHeartbeat();
|
|
140
|
+
}, 5 * 60000));
|
|
141
|
+
|
|
142
|
+
// doStats every 60s
|
|
143
|
+
// doStats()
|
|
144
|
+
|
|
145
|
+
if (this.topics.size > 0) {
|
|
146
|
+
// wait for this first onSettingsCommand call
|
|
147
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
148
|
+
await new Promise<void>((resolve, reject) => {
|
|
149
|
+
this.#startupReject = reject;
|
|
150
|
+
this.#startupResolve = resolve;
|
|
151
|
+
});
|
|
152
|
+
this.#startupReject = undefined;
|
|
153
|
+
this.#startupResolve = undefined;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
async shutdown() {
|
|
158
|
+
this.logger.info('Begin to shutdown the rocketmq client, clientId=%s', this.clientId);
|
|
159
|
+
while (this.#timers.length > 0) {
|
|
160
|
+
const timer = this.#timers.pop();
|
|
161
|
+
clearInterval(timer);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
await this.#notifyClientTermination();
|
|
165
|
+
|
|
166
|
+
this.logger.info('Begin to release all telemetry sessions, clientId=%s', this.clientId);
|
|
167
|
+
this.#releaseTelemetrySessions();
|
|
168
|
+
this.logger.info('Release all telemetry sessions successfully, clientId=%s', this.clientId);
|
|
169
|
+
|
|
170
|
+
this.rpcClientManager.close();
|
|
171
|
+
this.logger.info('Shutdown the rocketmq client successfully, clientId=%s', this.clientId);
|
|
172
|
+
this.logger.close && this.logger.close();
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
async #doHeartbeat() {
|
|
176
|
+
const request = this.wrapHeartbeatRequest();
|
|
177
|
+
for (const endpoints of this.getTotalRouteEndpoints()) {
|
|
178
|
+
await this.rpcClientManager.heartbeat(endpoints, request, this.requestTimeout);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
#getTotalRouteEndpointsMap() {
|
|
183
|
+
const endpointsMap = new Map<string, Endpoints>();
|
|
184
|
+
for (const topicRoute of this.topicRouteCache.values()) {
|
|
185
|
+
for (const endpoints of topicRoute.getTotalEndpoints()) {
|
|
186
|
+
endpointsMap.set(endpoints.facade, endpoints);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return endpointsMap;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
protected getTotalRouteEndpoints() {
|
|
193
|
+
const endpointsMap = this.#getTotalRouteEndpointsMap();
|
|
194
|
+
return Array.from(endpointsMap.values());
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
protected findNewRouteEndpoints(endpointsList: Endpoints[]) {
|
|
198
|
+
const endpointsMap = this.#getTotalRouteEndpointsMap();
|
|
199
|
+
const newEndpoints: Endpoints[] = [];
|
|
200
|
+
for (const endpoints of endpointsList) {
|
|
201
|
+
if (!endpointsMap.has(endpoints.facade)) {
|
|
202
|
+
newEndpoints.push(endpoints);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return newEndpoints;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
protected async updateRoutes() {
|
|
209
|
+
for (const topic of this.topics) {
|
|
210
|
+
await this.#fetchTopicRoute(topic);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
protected async getRouteData(topic: string) {
|
|
215
|
+
let topicRouteData = this.topicRouteCache.get(topic);
|
|
216
|
+
if (!topicRouteData) {
|
|
217
|
+
this.topics.add(topic);
|
|
218
|
+
topicRouteData = await this.#fetchTopicRoute(topic);
|
|
219
|
+
}
|
|
220
|
+
return topicRouteData;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
async #fetchTopicRoute(topic: string) {
|
|
224
|
+
const req = new QueryRouteRequest();
|
|
225
|
+
req.setTopic(createResource(topic));
|
|
226
|
+
req.setEndpoints(this.endpoints.toProtobuf());
|
|
227
|
+
const response = await this.rpcClientManager.queryRoute(this.endpoints, req, this.requestTimeout);
|
|
228
|
+
StatusChecker.check(response.getStatus()?.toObject());
|
|
229
|
+
const topicRouteData = new TopicRouteData(response.getMessageQueuesList());
|
|
230
|
+
const newEndpoints = this.findNewRouteEndpoints(topicRouteData.getTotalEndpoints());
|
|
231
|
+
for (const endpoints of newEndpoints) {
|
|
232
|
+
// sync current settings to new endpoints
|
|
233
|
+
this.getTelemetrySession(endpoints).syncSettings();
|
|
234
|
+
}
|
|
235
|
+
this.topicRouteCache.set(topic, topicRouteData);
|
|
236
|
+
this.onTopicRouteDataUpdate(topic, topicRouteData);
|
|
237
|
+
debug('fetchTopicRoute topic=%o topicRouteData=%j', topic, topicRouteData);
|
|
238
|
+
return topicRouteData;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
#syncSettings() {
|
|
242
|
+
const command = this.settingsCommand();
|
|
243
|
+
for (const endpoints of this.getTotalRouteEndpoints()) {
|
|
244
|
+
this.telemetry(endpoints, command);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
settingsCommand() {
|
|
249
|
+
const command = new TelemetryCommand();
|
|
250
|
+
command.setSettings(this.getSettings().toProtobuf());
|
|
251
|
+
return command;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
getTelemetrySession(endpoints: Endpoints) {
|
|
255
|
+
let session = this.#telemetrySessions.get(endpoints.facade);
|
|
256
|
+
if (!session) {
|
|
257
|
+
session = new TelemetrySession(this, endpoints, this.logger);
|
|
258
|
+
this.#telemetrySessions.set(endpoints.facade, session);
|
|
259
|
+
}
|
|
260
|
+
return session;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
createTelemetryStream(endpoints: Endpoints) {
|
|
264
|
+
const metadata = this.getRequestMetadata();
|
|
265
|
+
return this.rpcClientManager.telemetry(endpoints, metadata);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
telemetry(endpoints: Endpoints, command: TelemetryCommand) {
|
|
269
|
+
this.getTelemetrySession(endpoints).write(command);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
getRequestMetadata() {
|
|
273
|
+
// https://github.com/apache/rocketmq-clients/blob/master/docs/transport.md
|
|
274
|
+
// Transport Header
|
|
275
|
+
const metadata = new Metadata();
|
|
276
|
+
// version of protocol
|
|
277
|
+
metadata.set('x-mq-protocol', 'v2');
|
|
278
|
+
// client unique identifier: mbp@78774@2@3549a8wsr
|
|
279
|
+
metadata.set('x-mq-client-id', this.clientId);
|
|
280
|
+
// current timestamp: 20210309T195445Z, DATE_TIME_FORMAT = "yyyyMMdd'T'HHmmss'Z'"
|
|
281
|
+
const dateTime = getRequestDateTime();
|
|
282
|
+
metadata.set('x-mq-date-time', dateTime);
|
|
283
|
+
// request id for each gRPC header: f122a1e0-dbcf-4ca4-9db7-221903354be7
|
|
284
|
+
metadata.set('x-mq-request-id', randomUUID());
|
|
285
|
+
// language of client
|
|
286
|
+
// FIXME: java.lang.IllegalArgumentException: No enum constant org.apache.rocketmq.remoting.protocol.LanguageCode.nodejs
|
|
287
|
+
// https://github.com/apache/rocketmq/blob/master/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/LanguageCode.java
|
|
288
|
+
metadata.set('x-mq-language', 'HTTP');
|
|
289
|
+
// version of client
|
|
290
|
+
metadata.set('x-mq-client-version', UserAgent.INSTANCE.version);
|
|
291
|
+
if (this.#sessionCredentials) {
|
|
292
|
+
if (this.#sessionCredentials.securityToken) {
|
|
293
|
+
metadata.set('x-mq-session-token', this.#sessionCredentials.securityToken);
|
|
294
|
+
}
|
|
295
|
+
const signature = sign(this.#sessionCredentials.accessSecret, dateTime);
|
|
296
|
+
const authorization = `MQv2-HMAC-SHA1 Credential=${this.#sessionCredentials.accessKey}, SignedHeaders=x-mq-date-time, Signature=${signature}`;
|
|
297
|
+
metadata.set('authorization', authorization);
|
|
298
|
+
}
|
|
299
|
+
return metadata;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
protected abstract getSettings(): Settings;
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Wrap heartbeat request
|
|
306
|
+
*/
|
|
307
|
+
protected abstract wrapHeartbeatRequest(): HeartbeatRequest;
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Wrap notify client termination request.
|
|
311
|
+
*/
|
|
312
|
+
protected abstract wrapNotifyClientTerminationRequest(): NotifyClientTerminationRequest;
|
|
313
|
+
|
|
314
|
+
#releaseTelemetrySessions() {
|
|
315
|
+
for (const session of this.#telemetrySessions.values()) {
|
|
316
|
+
session.release();
|
|
317
|
+
}
|
|
318
|
+
this.#telemetrySessions.clear();
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Notify remote that current client is prepared to be terminated.
|
|
323
|
+
*/
|
|
324
|
+
async #notifyClientTermination() {
|
|
325
|
+
this.logger.info('Notify remote that client is terminated, clientId=%s', this.clientId);
|
|
326
|
+
const request = this.wrapNotifyClientTerminationRequest();
|
|
327
|
+
for (const endpoints of this.getTotalRouteEndpoints()) {
|
|
328
|
+
await this.rpcClientManager.notifyClientTermination(endpoints, request, this.requestTimeout);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
333
|
+
protected onTopicRouteDataUpdate(_topic: string, _topicRouteData: TopicRouteData) {
|
|
334
|
+
// sub class can monitor topic route data change here
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
onUnknownCommand(endpoints: Endpoints, status: Status.AsObject) {
|
|
338
|
+
try {
|
|
339
|
+
StatusChecker.check(status);
|
|
340
|
+
} catch (err) {
|
|
341
|
+
this.logger.error('Get error status from telemetry session, status=%j, endpoints=%j, clientId=%s',
|
|
342
|
+
status, endpoints, this.clientId);
|
|
343
|
+
this.#startupReject && this.#startupReject(err as ClientException);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
onSettingsCommand(_endpoints: Endpoints, settings: SettingsPB) {
|
|
348
|
+
// final Metric metric = new Metric(settings.getMetric());
|
|
349
|
+
// clientMeterManager.reset(metric);
|
|
350
|
+
this.getSettings().sync(settings);
|
|
351
|
+
this.logger.info('Sync settings=%j, clientId=%s', this.getSettings(), this.clientId);
|
|
352
|
+
this.#startupResolve && this.#startupResolve();
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
onRecoverOrphanedTransactionCommand(_endpoints: Endpoints, command: RecoverOrphanedTransactionCommand) {
|
|
356
|
+
this.logger.warn('Ignore orphaned transaction recovery command from remote, which is not expected, clientId=%s, command=%j',
|
|
357
|
+
this.clientId, command.toObject());
|
|
358
|
+
// const telemetryCommand = new TelemetryCommand();
|
|
359
|
+
// telemetryCommand.setStatus(new Status().setCode(Code.NOT_IMPLEMENTED));
|
|
360
|
+
// telemetryCommand.setRecoverOrphanedTransactionCommand(new RecoverOrphanedTransactionCommand());
|
|
361
|
+
// this.telemetry(endpoints, telemetryCommand);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
onVerifyMessageCommand(endpoints: Endpoints, command: VerifyMessageCommand) {
|
|
365
|
+
const obj = command.toObject();
|
|
366
|
+
this.logger.warn('Ignore verify message command from remote, which is not expected, clientId=%s, command=%j',
|
|
367
|
+
this.clientId, obj);
|
|
368
|
+
const telemetryCommand = new TelemetryCommand();
|
|
369
|
+
telemetryCommand.setStatus(new Status().setCode(Code.NOT_IMPLEMENTED));
|
|
370
|
+
telemetryCommand.setVerifyMessageCommand(new VerifyMessageCommand().setNonce(obj.nonce));
|
|
371
|
+
this.telemetry(endpoints, telemetryCommand);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
onPrintThreadStackTraceCommand(endpoints: Endpoints, command: PrintThreadStackTraceCommand) {
|
|
375
|
+
const obj = command.toObject();
|
|
376
|
+
this.logger.warn('Ignore orphaned transaction recovery command from remote, which is not expected, clientId=%s, command=%j',
|
|
377
|
+
this.clientId, obj);
|
|
378
|
+
const nonce = obj.nonce;
|
|
379
|
+
const telemetryCommand = new TelemetryCommand();
|
|
380
|
+
telemetryCommand.setThreadStackTrace(new ThreadStackTrace().setThreadStackTrace('mock stack').setNonce(nonce));
|
|
381
|
+
telemetryCommand.setStatus(new Status().setCode(Code.OK));
|
|
382
|
+
this.telemetry(endpoints, telemetryCommand);
|
|
383
|
+
}
|
|
384
|
+
}
|