rocketmq-client-nodejs-bate 1.0.12
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 +186 -0
- package/dist/client/BaseClient.d.ts +95 -0
- package/dist/client/BaseClient.js +324 -0
- package/dist/client/ClientId.d.ts +24 -0
- package/dist/client/ClientId.js +33 -0
- package/dist/client/Logger.d.ts +25 -0
- package/dist/client/Logger.js +33 -0
- package/dist/client/RpcClient.d.ts +48 -0
- package/dist/client/RpcClient.js +219 -0
- package/dist/client/RpcClientManager.d.ts +42 -0
- package/dist/client/RpcClientManager.js +144 -0
- package/dist/client/SessionCredentials.d.ts +21 -0
- package/dist/client/SessionCredentials.js +19 -0
- package/dist/client/Settings.d.ts +31 -0
- package/dist/client/Settings.js +40 -0
- package/dist/client/TelemetrySession.d.ts +27 -0
- package/dist/client/TelemetrySession.js +110 -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/Assignment.d.ts +23 -0
- package/dist/consumer/Assignment.js +40 -0
- package/dist/consumer/Assignments.d.ts +24 -0
- package/dist/consumer/Assignments.js +47 -0
- package/dist/consumer/ConsumeResult.d.ts +20 -0
- package/dist/consumer/ConsumeResult.js +25 -0
- package/dist/consumer/ConsumeService.d.ts +28 -0
- package/dist/consumer/ConsumeService.js +49 -0
- package/dist/consumer/ConsumeTask.d.ts +24 -0
- package/dist/consumer/ConsumeTask.js +40 -0
- package/dist/consumer/Consumer.d.ts +38 -0
- package/dist/consumer/Consumer.js +111 -0
- package/dist/consumer/FifoConsumeService.d.ts +25 -0
- package/dist/consumer/FifoConsumeService.js +123 -0
- package/dist/consumer/FilterExpression.d.ts +25 -0
- package/dist/consumer/FilterExpression.js +40 -0
- package/dist/consumer/MessageListener.d.ts +21 -0
- package/dist/consumer/MessageListener.js +19 -0
- package/dist/consumer/ProcessQueue.d.ts +39 -0
- package/dist/consumer/ProcessQueue.js +286 -0
- package/dist/consumer/PushConsumer.d.ts +68 -0
- package/dist/consumer/PushConsumer.js +377 -0
- package/dist/consumer/PushSubscriptionSettings.d.ts +31 -0
- package/dist/consumer/PushSubscriptionSettings.js +97 -0
- package/dist/consumer/SimpleConsumer.d.ts +50 -0
- package/dist/consumer/SimpleConsumer.js +122 -0
- package/dist/consumer/SimpleSubscriptionSettings.d.ts +28 -0
- package/dist/consumer/SimpleSubscriptionSettings.js +57 -0
- package/dist/consumer/StandardConsumeService.d.ts +24 -0
- package/dist/consumer/StandardConsumeService.js +42 -0
- package/dist/consumer/SubscriptionLoadBalancer.d.ts +23 -0
- package/dist/consumer/SubscriptionLoadBalancer.js +46 -0
- package/dist/consumer/index.d.ts +32 -0
- package/dist/consumer/index.js +49 -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 -0
- package/dist/index.js +39 -0
- package/dist/message/Message.d.ts +38 -0
- package/dist/message/Message.js +57 -0
- package/dist/message/MessageId.d.ts +59 -0
- package/dist/message/MessageId.js +123 -0
- package/dist/message/MessageView.d.ts +38 -0
- package/dist/message/MessageView.js +90 -0
- package/dist/message/PublishingMessage.d.ts +30 -0
- package/dist/message/PublishingMessage.js +100 -0
- package/dist/message/index.d.ts +20 -0
- package/dist/message/index.js +37 -0
- package/dist/producer/Producer.d.ts +55 -0
- package/dist/producer/Producer.js +318 -0
- 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/RecallReceipt.d.ts +25 -0
- package/dist/producer/RecallReceipt.js +34 -0
- package/dist/producer/SendReceipt.d.ts +29 -0
- package/dist/producer/SendReceipt.js +60 -0
- package/dist/producer/Transaction.d.ts +28 -0
- package/dist/producer/Transaction.js +70 -0
- package/dist/producer/TransactionChecker.d.ts +21 -0
- package/dist/producer/TransactionChecker.js +19 -0
- package/dist/producer/index.d.ts +22 -0
- package/dist/producer/index.js +40 -0
- package/dist/retry/ExponentialBackoffRetryPolicy.d.ts +27 -0
- package/dist/retry/ExponentialBackoffRetryPolicy.js +64 -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 +35 -0
- package/dist/util/index.js +88 -0
- package/package.json +62 -0
- package/proto/apache/rocketmq/v2/admin.proto +43 -0
- package/proto/apache/rocketmq/v2/admin_grpc_pb.d.ts +41 -0
- package/proto/apache/rocketmq/v2/admin_grpc_pb.js +60 -0
- package/proto/apache/rocketmq/v2/admin_pb.d.ts +56 -0
- package/proto/apache/rocketmq/v2/admin_pb.js +340 -0
- package/proto/apache/rocketmq/v2/definition.proto +570 -0
- package/proto/apache/rocketmq/v2/definition_grpc_pb.js +1 -0
- package/proto/apache/rocketmq/v2/definition_pb.d.ts +885 -0
- package/proto/apache/rocketmq/v2/definition_pb.js +6141 -0
- package/proto/apache/rocketmq/v2/service.proto +443 -0
- package/proto/apache/rocketmq/v2/service_grpc_pb.d.ts +294 -0
- package/proto/apache/rocketmq/v2/service_grpc_pb.js +637 -0
- package/proto/apache/rocketmq/v2/service_pb.d.ts +1249 -0
- package/proto/apache/rocketmq/v2/service_pb.js +9723 -0
- package/src/client/BaseClient.ts +404 -0
- package/src/client/ClientId.ts +31 -0
- package/src/client/Logger.ts +36 -0
- package/src/client/RpcClient.ts +258 -0
- package/src/client/RpcClientManager.ts +180 -0
- package/src/client/SessionCredentials.ts +22 -0
- package/src/client/Settings.ts +46 -0
- package/src/client/TelemetrySession.ts +130 -0
- package/src/client/UserAgent.ts +45 -0
- package/src/client/index.ts +27 -0
- package/src/consumer/Assignment.ts +39 -0
- package/src/consumer/Assignments.ts +46 -0
- package/src/consumer/ConsumeResult.ts +21 -0
- package/src/consumer/ConsumeService.ts +54 -0
- package/src/consumer/ConsumeTask.ts +40 -0
- package/src/consumer/Consumer.ts +129 -0
- package/src/consumer/FifoConsumeService.ts +136 -0
- package/src/consumer/FilterExpression.ts +42 -0
- package/src/consumer/MessageListener.ts +23 -0
- package/src/consumer/ProcessQueue.ts +326 -0
- package/src/consumer/PushConsumer.ts +473 -0
- package/src/consumer/PushSubscriptionSettings.ts +123 -0
- package/src/consumer/SimpleConsumer.ts +153 -0
- package/src/consumer/SimpleSubscriptionSettings.ts +64 -0
- package/src/consumer/StandardConsumeService.ts +44 -0
- package/src/consumer/SubscriptionLoadBalancer.ts +47 -0
- package/src/consumer/index.ts +33 -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 -0
- package/src/message/Message.ts +67 -0
- package/src/message/MessageId.ts +123 -0
- package/src/message/MessageView.ts +94 -0
- package/src/message/PublishingMessage.ts +104 -0
- package/src/message/index.ts +21 -0
- package/src/producer/Producer.ts +388 -0
- package/src/producer/PublishingLoadBalancer.ts +85 -0
- package/src/producer/PublishingSettings.ts +78 -0
- package/src/producer/RecallReceipt.ts +32 -0
- package/src/producer/SendReceipt.ts +63 -0
- package/src/producer/Transaction.ts +86 -0
- package/src/producer/TransactionChecker.ts +23 -0
- package/src/producer/index.ts +24 -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
|
@@ -0,0 +1,258 @@
|
|
|
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 { ChannelCredentials, Metadata } from '@grpc/grpc-js';
|
|
19
|
+
import { MessagingServiceClient } from '../../proto/apache/rocketmq/v2/service_grpc_pb';
|
|
20
|
+
import {
|
|
21
|
+
AckMessageRequest,
|
|
22
|
+
AckMessageResponse,
|
|
23
|
+
ChangeInvisibleDurationRequest,
|
|
24
|
+
ChangeInvisibleDurationResponse,
|
|
25
|
+
EndTransactionRequest,
|
|
26
|
+
EndTransactionResponse,
|
|
27
|
+
ForwardMessageToDeadLetterQueueRequest,
|
|
28
|
+
ForwardMessageToDeadLetterQueueResponse,
|
|
29
|
+
GetOffsetRequest,
|
|
30
|
+
GetOffsetResponse,
|
|
31
|
+
HeartbeatRequest,
|
|
32
|
+
HeartbeatResponse,
|
|
33
|
+
NotifyClientTerminationRequest,
|
|
34
|
+
NotifyClientTerminationResponse,
|
|
35
|
+
PullMessageRequest,
|
|
36
|
+
PullMessageResponse,
|
|
37
|
+
QueryAssignmentRequest,
|
|
38
|
+
QueryAssignmentResponse,
|
|
39
|
+
QueryOffsetRequest,
|
|
40
|
+
QueryOffsetResponse,
|
|
41
|
+
QueryRouteRequest,
|
|
42
|
+
QueryRouteResponse,
|
|
43
|
+
RecallMessageRequest,
|
|
44
|
+
RecallMessageResponse,
|
|
45
|
+
ReceiveMessageRequest,
|
|
46
|
+
ReceiveMessageResponse,
|
|
47
|
+
SendMessageRequest,
|
|
48
|
+
SendMessageResponse,
|
|
49
|
+
UpdateOffsetRequest,
|
|
50
|
+
UpdateOffsetResponse,
|
|
51
|
+
} from '../../proto/apache/rocketmq/v2/service_pb';
|
|
52
|
+
import { Endpoints } from '../route';
|
|
53
|
+
|
|
54
|
+
export class RpcClient {
|
|
55
|
+
#client: MessagingServiceClient;
|
|
56
|
+
#activityTime = Date.now();
|
|
57
|
+
|
|
58
|
+
constructor(endpoints: Endpoints, sslEnabled: boolean) {
|
|
59
|
+
const address = endpoints.getGrpcTarget();
|
|
60
|
+
const grpcCredentials = sslEnabled ? ChannelCredentials.createSsl() : ChannelCredentials.createInsecure();
|
|
61
|
+
this.#client = new MessagingServiceClient(address, grpcCredentials);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
#getAndActivityRpcClient() {
|
|
65
|
+
this.#activityTime = Date.now();
|
|
66
|
+
return this.#client;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
#getDeadline(duration: number) {
|
|
70
|
+
return Date.now() + duration;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
idleDuration() {
|
|
74
|
+
return Date.now() - this.#activityTime;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
close() {
|
|
78
|
+
this.#client.close();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Query topic route
|
|
83
|
+
*
|
|
84
|
+
* @param request query route request.
|
|
85
|
+
* @param metadata gRPC request header metadata.
|
|
86
|
+
* @param duration request max duration in milliseconds.
|
|
87
|
+
*/
|
|
88
|
+
async queryRoute(request: QueryRouteRequest, metadata: Metadata, duration: number) {
|
|
89
|
+
const client = this.#getAndActivityRpcClient();
|
|
90
|
+
const deadline = this.#getDeadline(duration);
|
|
91
|
+
return new Promise<QueryRouteResponse>((resolve, reject) => {
|
|
92
|
+
client.queryRoute(request, metadata, { deadline }, (e, res) => {
|
|
93
|
+
if (e) return reject(e);
|
|
94
|
+
resolve(res);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async heartbeat(request: HeartbeatRequest, metadata: Metadata, duration: number) {
|
|
100
|
+
const client = this.#getAndActivityRpcClient();
|
|
101
|
+
const deadline = this.#getDeadline(duration);
|
|
102
|
+
return new Promise<HeartbeatResponse>((resolve, reject) => {
|
|
103
|
+
client.heartbeat(request, metadata, { deadline }, (e, res) => {
|
|
104
|
+
if (e) return reject(e);
|
|
105
|
+
resolve(res);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async sendMessage(request: SendMessageRequest, metadata: Metadata, duration: number) {
|
|
111
|
+
const client = this.#getAndActivityRpcClient();
|
|
112
|
+
const deadline = this.#getDeadline(duration);
|
|
113
|
+
return new Promise<SendMessageResponse>((resolve, reject) => {
|
|
114
|
+
client.sendMessage(request, metadata, { deadline }, (e, res) => {
|
|
115
|
+
if (e) return reject(e);
|
|
116
|
+
resolve(res);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async queryAssignment(request: QueryAssignmentRequest, metadata: Metadata, duration: number) {
|
|
122
|
+
const client = this.#getAndActivityRpcClient();
|
|
123
|
+
const deadline = this.#getDeadline(duration);
|
|
124
|
+
return new Promise<QueryAssignmentResponse>((resolve, reject) => {
|
|
125
|
+
client.queryAssignment(request, metadata, { deadline }, (e, res) => {
|
|
126
|
+
if (e) return reject(e);
|
|
127
|
+
resolve(res);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async receiveMessage(request: ReceiveMessageRequest, metadata: Metadata, duration: number) {
|
|
133
|
+
const client = this.#getAndActivityRpcClient();
|
|
134
|
+
const deadline = this.#getDeadline(duration);
|
|
135
|
+
const readable = client.receiveMessage(request, metadata, { deadline });
|
|
136
|
+
const responses: ReceiveMessageResponse[] = [];
|
|
137
|
+
for await (const res of readable) {
|
|
138
|
+
responses.push(res);
|
|
139
|
+
}
|
|
140
|
+
return responses;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async ackMessage(request: AckMessageRequest, metadata: Metadata, duration: number) {
|
|
144
|
+
const client = this.#getAndActivityRpcClient();
|
|
145
|
+
const deadline = this.#getDeadline(duration);
|
|
146
|
+
return new Promise<AckMessageResponse>((resolve, reject) => {
|
|
147
|
+
client.ackMessage(request, metadata, { deadline }, (e, res) => {
|
|
148
|
+
if (e) return reject(e);
|
|
149
|
+
resolve(res);
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async forwardMessageToDeadLetterQueue(request: ForwardMessageToDeadLetterQueueRequest,
|
|
155
|
+
metadata: Metadata, duration: number) {
|
|
156
|
+
const client = this.#getAndActivityRpcClient();
|
|
157
|
+
const deadline = this.#getDeadline(duration);
|
|
158
|
+
return new Promise<ForwardMessageToDeadLetterQueueResponse>((resolve, reject) => {
|
|
159
|
+
client.forwardMessageToDeadLetterQueue(request, metadata, { deadline }, (e, res) => {
|
|
160
|
+
if (e) return reject(e);
|
|
161
|
+
resolve(res);
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
async pullMessage(request: PullMessageRequest, metadata: Metadata, duration: number) {
|
|
167
|
+
const client = this.#getAndActivityRpcClient();
|
|
168
|
+
const deadline = this.#getDeadline(duration);
|
|
169
|
+
const readable = client.pullMessage(request, metadata, { deadline });
|
|
170
|
+
const responses: PullMessageResponse[] = [];
|
|
171
|
+
for await (const res of readable) {
|
|
172
|
+
responses.push(res);
|
|
173
|
+
}
|
|
174
|
+
return responses;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
async updateOffset(request: UpdateOffsetRequest, metadata: Metadata, duration: number) {
|
|
178
|
+
const client = this.#getAndActivityRpcClient();
|
|
179
|
+
const deadline = this.#getDeadline(duration);
|
|
180
|
+
return new Promise<UpdateOffsetResponse>((resolve, reject) => {
|
|
181
|
+
client.updateOffset(request, metadata, { deadline }, (e, res) => {
|
|
182
|
+
if (e) return reject(e);
|
|
183
|
+
resolve(res);
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
async getOffset(request: GetOffsetRequest, metadata: Metadata, duration: number) {
|
|
189
|
+
const client = this.#getAndActivityRpcClient();
|
|
190
|
+
const deadline = this.#getDeadline(duration);
|
|
191
|
+
return new Promise<GetOffsetResponse>((resolve, reject) => {
|
|
192
|
+
client.getOffset(request, metadata, { deadline }, (e, res) => {
|
|
193
|
+
if (e) return reject(e);
|
|
194
|
+
resolve(res);
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
async queryOffset(request: QueryOffsetRequest, metadata: Metadata, duration: number) {
|
|
200
|
+
const client = this.#getAndActivityRpcClient();
|
|
201
|
+
const deadline = this.#getDeadline(duration);
|
|
202
|
+
return new Promise<QueryOffsetResponse>((resolve, reject) => {
|
|
203
|
+
client.queryOffset(request, metadata, { deadline }, (e, res) => {
|
|
204
|
+
if (e) return reject(e);
|
|
205
|
+
resolve(res);
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
async endTransaction(request: EndTransactionRequest, metadata: Metadata, duration: number) {
|
|
211
|
+
const client = this.#getAndActivityRpcClient();
|
|
212
|
+
const deadline = this.#getDeadline(duration);
|
|
213
|
+
return new Promise<EndTransactionResponse>((resolve, reject) => {
|
|
214
|
+
client.endTransaction(request, metadata, { deadline }, (e, res) => {
|
|
215
|
+
if (e) return reject(e);
|
|
216
|
+
resolve(res);
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
telemetry(metadata: Metadata) {
|
|
222
|
+
const client = this.#getAndActivityRpcClient();
|
|
223
|
+
return client.telemetry(metadata);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
async notifyClientTermination(request: NotifyClientTerminationRequest, metadata: Metadata, duration: number) {
|
|
227
|
+
const client = this.#getAndActivityRpcClient();
|
|
228
|
+
const deadline = this.#getDeadline(duration);
|
|
229
|
+
return new Promise<NotifyClientTerminationResponse>((resolve, reject) => {
|
|
230
|
+
client.notifyClientTermination(request, metadata, { deadline }, (e, res) => {
|
|
231
|
+
if (e) return reject(e);
|
|
232
|
+
resolve(res);
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
async changeInvisibleDuration(request: ChangeInvisibleDurationRequest, metadata: Metadata, duration: number) {
|
|
238
|
+
const client = this.#getAndActivityRpcClient();
|
|
239
|
+
const deadline = this.#getDeadline(duration);
|
|
240
|
+
return new Promise<ChangeInvisibleDurationResponse>((resolve, reject) => {
|
|
241
|
+
client.changeInvisibleDuration(request, metadata, { deadline }, (e, res) => {
|
|
242
|
+
if (e) return reject(e);
|
|
243
|
+
resolve(res);
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
async recallMessage(request: RecallMessageRequest, metadata: Metadata, duration: number) {
|
|
249
|
+
const client = this.#getAndActivityRpcClient();
|
|
250
|
+
const deadline = this.#getDeadline(duration);
|
|
251
|
+
return new Promise<RecallMessageResponse>((resolve, reject) => {
|
|
252
|
+
client.recallMessage(request, metadata, { deadline }, (e, res) => {
|
|
253
|
+
if (e) return reject(e);
|
|
254
|
+
resolve(res);
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
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 { Metadata } from '@grpc/grpc-js';
|
|
19
|
+
import {
|
|
20
|
+
AckMessageRequest,
|
|
21
|
+
ChangeInvisibleDurationRequest,
|
|
22
|
+
EndTransactionRequest,
|
|
23
|
+
ForwardMessageToDeadLetterQueueRequest,
|
|
24
|
+
GetOffsetRequest,
|
|
25
|
+
HeartbeatRequest, NotifyClientTerminationRequest, PullMessageRequest,
|
|
26
|
+
QueryAssignmentRequest, QueryOffsetRequest, QueryRouteRequest,
|
|
27
|
+
ReceiveMessageRequest, SendMessageRequest, UpdateOffsetRequest,
|
|
28
|
+
RecallMessageRequest,
|
|
29
|
+
} from '../../proto/apache/rocketmq/v2/service_pb';
|
|
30
|
+
import { Endpoints } from '../route';
|
|
31
|
+
import { ILogger } from './Logger';
|
|
32
|
+
import { RpcClient } from './RpcClient';
|
|
33
|
+
import type { BaseClient } from './BaseClient';
|
|
34
|
+
|
|
35
|
+
const RPC_CLIENT_MAX_IDLE_DURATION = 30 * 60000; // 30 minutes
|
|
36
|
+
const RPC_CLIENT_IDLE_CHECK_PERIOD = 60000;
|
|
37
|
+
|
|
38
|
+
export class RpcClientManager {
|
|
39
|
+
#rpcClients = new Map<Endpoints, RpcClient>();
|
|
40
|
+
#baseClient: BaseClient;
|
|
41
|
+
#logger: ILogger;
|
|
42
|
+
#clearIdleRpcClientsTimer: NodeJS.Timeout;
|
|
43
|
+
|
|
44
|
+
constructor(baseClient: BaseClient, logger: ILogger) {
|
|
45
|
+
this.#baseClient = baseClient;
|
|
46
|
+
this.#logger = logger;
|
|
47
|
+
this.#startUp();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
#startUp() {
|
|
51
|
+
this.#clearIdleRpcClientsTimer = setInterval(() => {
|
|
52
|
+
this.#clearIdleRpcClients();
|
|
53
|
+
}, RPC_CLIENT_IDLE_CHECK_PERIOD);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
#clearIdleRpcClients() {
|
|
57
|
+
for (const [ endpoints, rpcClient ] of this.#rpcClients.entries()) {
|
|
58
|
+
const idleDuration = rpcClient.idleDuration();
|
|
59
|
+
if (idleDuration > RPC_CLIENT_MAX_IDLE_DURATION) {
|
|
60
|
+
rpcClient.close();
|
|
61
|
+
this.#rpcClients.delete(endpoints);
|
|
62
|
+
this.#logger.info('[RpcClientManager] Rpc client has been idle for a long time, endpoints=%s, idleDuration=%s, clientId=%s',
|
|
63
|
+
endpoints, idleDuration, RPC_CLIENT_MAX_IDLE_DURATION, this.#baseClient.clientId);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
#getRpcClient(endpoints: Endpoints) {
|
|
69
|
+
let rpcClient = this.#rpcClients.get(endpoints);
|
|
70
|
+
if (!rpcClient) {
|
|
71
|
+
rpcClient = new RpcClient(endpoints, this.#baseClient.sslEnabled);
|
|
72
|
+
this.#rpcClients.set(endpoints, rpcClient);
|
|
73
|
+
}
|
|
74
|
+
return rpcClient;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
close() {
|
|
78
|
+
for (const [ endpoints, rpcClient ] of this.#rpcClients.entries()) {
|
|
79
|
+
rpcClient.close();
|
|
80
|
+
this.#rpcClients.delete(endpoints);
|
|
81
|
+
}
|
|
82
|
+
clearInterval(this.#clearIdleRpcClientsTimer);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async queryRoute(endpoints: Endpoints, request: QueryRouteRequest, duration: number) {
|
|
86
|
+
const rpcClient = this.#getRpcClient(endpoints);
|
|
87
|
+
const metadata = this.#baseClient.getRequestMetadata();
|
|
88
|
+
return await rpcClient.queryRoute(request, metadata, duration);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async heartbeat(endpoints: Endpoints, request: HeartbeatRequest, duration: number) {
|
|
92
|
+
const rpcClient = this.#getRpcClient(endpoints);
|
|
93
|
+
const metadata = this.#baseClient.getRequestMetadata();
|
|
94
|
+
return await rpcClient.heartbeat(request, metadata, duration);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async sendMessage(endpoints: Endpoints, request: SendMessageRequest, duration: number) {
|
|
98
|
+
const rpcClient = this.#getRpcClient(endpoints);
|
|
99
|
+
const metadata = this.#baseClient.getRequestMetadata();
|
|
100
|
+
return await rpcClient.sendMessage(request, metadata, duration);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async queryAssignment(endpoints: Endpoints, request: QueryAssignmentRequest, duration: number) {
|
|
104
|
+
const rpcClient = this.#getRpcClient(endpoints);
|
|
105
|
+
const metadata = this.#baseClient.getRequestMetadata();
|
|
106
|
+
return await rpcClient.queryAssignment(request, metadata, duration);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async receiveMessage(endpoints: Endpoints, request: ReceiveMessageRequest, duration: number) {
|
|
110
|
+
const rpcClient = this.#getRpcClient(endpoints);
|
|
111
|
+
const metadata = this.#baseClient.getRequestMetadata();
|
|
112
|
+
return await rpcClient.receiveMessage(request, metadata, duration);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async ackMessage(endpoints: Endpoints, request: AckMessageRequest, duration: number) {
|
|
116
|
+
const rpcClient = this.#getRpcClient(endpoints);
|
|
117
|
+
const metadata = this.#baseClient.getRequestMetadata();
|
|
118
|
+
return await rpcClient.ackMessage(request, metadata, duration);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async forwardMessageToDeadLetterQueue(endpoints: Endpoints, request: ForwardMessageToDeadLetterQueueRequest,
|
|
122
|
+
duration: number) {
|
|
123
|
+
const rpcClient = this.#getRpcClient(endpoints);
|
|
124
|
+
const metadata = this.#baseClient.getRequestMetadata();
|
|
125
|
+
return await rpcClient.forwardMessageToDeadLetterQueue(request, metadata, duration);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async pullMessage(endpoints: Endpoints, request: PullMessageRequest, duration: number) {
|
|
129
|
+
const rpcClient = this.#getRpcClient(endpoints);
|
|
130
|
+
const metadata = this.#baseClient.getRequestMetadata();
|
|
131
|
+
return await rpcClient.pullMessage(request, metadata, duration);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async updateOffset(endpoints: Endpoints, request: UpdateOffsetRequest, duration: number) {
|
|
135
|
+
const rpcClient = this.#getRpcClient(endpoints);
|
|
136
|
+
const metadata = this.#baseClient.getRequestMetadata();
|
|
137
|
+
return await rpcClient.updateOffset(request, metadata, duration);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async getOffset(endpoints: Endpoints, request: GetOffsetRequest, duration: number) {
|
|
141
|
+
const rpcClient = this.#getRpcClient(endpoints);
|
|
142
|
+
const metadata = this.#baseClient.getRequestMetadata();
|
|
143
|
+
return await rpcClient.getOffset(request, metadata, duration);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async queryOffset(endpoints: Endpoints, request: QueryOffsetRequest, duration: number) {
|
|
147
|
+
const rpcClient = this.#getRpcClient(endpoints);
|
|
148
|
+
const metadata = this.#baseClient.getRequestMetadata();
|
|
149
|
+
return await rpcClient.queryOffset(request, metadata, duration);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async endTransaction(endpoints: Endpoints, request: EndTransactionRequest, duration: number) {
|
|
153
|
+
const rpcClient = this.#getRpcClient(endpoints);
|
|
154
|
+
const metadata = this.#baseClient.getRequestMetadata();
|
|
155
|
+
return await rpcClient.endTransaction(request, metadata, duration);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
telemetry(endpoints: Endpoints, metadata: Metadata) {
|
|
159
|
+
const rpcClient = this.#getRpcClient(endpoints);
|
|
160
|
+
return rpcClient.telemetry(metadata);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async changeInvisibleDuration(endpoints: Endpoints, request: ChangeInvisibleDurationRequest, duration: number) {
|
|
164
|
+
const rpcClient = this.#getRpcClient(endpoints);
|
|
165
|
+
const metadata = this.#baseClient.getRequestMetadata();
|
|
166
|
+
return await rpcClient.changeInvisibleDuration(request, metadata, duration);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async notifyClientTermination(endpoints: Endpoints, request: NotifyClientTerminationRequest, duration: number) {
|
|
170
|
+
const rpcClient = this.#getRpcClient(endpoints);
|
|
171
|
+
const metadata = this.#baseClient.getRequestMetadata();
|
|
172
|
+
return await rpcClient.notifyClientTermination(request, metadata, duration);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
async recallMessage(endpoints: Endpoints, request: RecallMessageRequest, duration: number) {
|
|
176
|
+
const rpcClient = this.#getRpcClient(endpoints);
|
|
177
|
+
const metadata = this.#baseClient.getRequestMetadata();
|
|
178
|
+
return await rpcClient.recallMessage(request, metadata, duration);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
export interface SessionCredentials {
|
|
19
|
+
accessKey: string;
|
|
20
|
+
accessSecret: string;
|
|
21
|
+
securityToken?: string;
|
|
22
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
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 { ClientType, Settings as SettingsPB } from '../../proto/apache/rocketmq/v2/definition_pb';
|
|
19
|
+
import { Endpoints } from '../route/Endpoints';
|
|
20
|
+
import { RetryPolicy } from '../retry';
|
|
21
|
+
|
|
22
|
+
export abstract class Settings {
|
|
23
|
+
protected readonly namespace: string;
|
|
24
|
+
protected readonly clientId: string;
|
|
25
|
+
protected readonly clientType: ClientType;
|
|
26
|
+
protected readonly accessPoint: Endpoints;
|
|
27
|
+
protected retryPolicy?: RetryPolicy;
|
|
28
|
+
protected readonly requestTimeout: number;
|
|
29
|
+
|
|
30
|
+
constructor(namespace: string, clientId: string, clientType: ClientType, accessPoint: Endpoints, requestTimeout: number, retryPolicy?: RetryPolicy) {
|
|
31
|
+
this.clientId = clientId;
|
|
32
|
+
this.namespace = namespace;
|
|
33
|
+
this.clientType = clientType;
|
|
34
|
+
this.accessPoint = accessPoint;
|
|
35
|
+
this.retryPolicy = retryPolicy;
|
|
36
|
+
this.requestTimeout = requestTimeout;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
abstract toProtobuf(): SettingsPB;
|
|
40
|
+
|
|
41
|
+
abstract sync(settings: SettingsPB): void;
|
|
42
|
+
|
|
43
|
+
getRetryPolicy() {
|
|
44
|
+
return this.retryPolicy;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
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 { ClientDuplexStream } from '@grpc/grpc-js';
|
|
19
|
+
import { TelemetryCommand } from '../../proto/apache/rocketmq/v2/service_pb';
|
|
20
|
+
import { Endpoints } from '../route';
|
|
21
|
+
import type { BaseClient } from './BaseClient';
|
|
22
|
+
import { ILogger } from './Logger';
|
|
23
|
+
|
|
24
|
+
export class TelemetrySession {
|
|
25
|
+
#endpoints: Endpoints;
|
|
26
|
+
#baseClient: BaseClient;
|
|
27
|
+
#logger: ILogger;
|
|
28
|
+
#stream: ClientDuplexStream<TelemetryCommand, TelemetryCommand>;
|
|
29
|
+
|
|
30
|
+
constructor(baseClient: BaseClient, endpoints: Endpoints, logger: ILogger) {
|
|
31
|
+
this.#endpoints = endpoints;
|
|
32
|
+
this.#baseClient = baseClient;
|
|
33
|
+
this.#logger = logger;
|
|
34
|
+
this.#logger.info('Creating telemetry session, endpoints=%s, clientId=%s',
|
|
35
|
+
endpoints, baseClient.clientId);
|
|
36
|
+
this.#renewStream(true);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
release() {
|
|
40
|
+
this.#logger.info('Begin to release telemetry session, endpoints=%s, clientId=%s',
|
|
41
|
+
this.#endpoints, this.#baseClient.clientId);
|
|
42
|
+
this.#stream.end();
|
|
43
|
+
this.#stream.removeAllListeners();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
write(command: TelemetryCommand) {
|
|
47
|
+
this.#stream.write(command);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
syncSettings() {
|
|
51
|
+
const command = this.#baseClient.settingsCommand();
|
|
52
|
+
this.write(command);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
#renewStream(inited: boolean) {
|
|
56
|
+
try {
|
|
57
|
+
this.#logger.debug?.('Creating telemetry stream, endpoints=%s, clientId=%s, inited=%s',
|
|
58
|
+
this.#endpoints, this.#baseClient.clientId, inited);
|
|
59
|
+
this.#stream = this.#baseClient.createTelemetryStream(this.#endpoints);
|
|
60
|
+
this.#stream.on('data', this.#onData.bind(this));
|
|
61
|
+
this.#stream.once('error', this.#onError.bind(this));
|
|
62
|
+
this.#stream.once('end', this.#onEnd.bind(this));
|
|
63
|
+
if (!inited) {
|
|
64
|
+
this.#logger.info('Syncing settings to new stream, endpoints=%s, clientId=%s',
|
|
65
|
+
this.#endpoints, this.#baseClient.clientId);
|
|
66
|
+
this.syncSettings();
|
|
67
|
+
}
|
|
68
|
+
} catch (err) {
|
|
69
|
+
this.#logger.error('Failed to create telemetry stream, endpoints=%s, clientId=%s, error=%s',
|
|
70
|
+
this.#endpoints, this.#baseClient.clientId, err);
|
|
71
|
+
throw err;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
#onData(command: TelemetryCommand) {
|
|
76
|
+
const endpoints = this.#endpoints;
|
|
77
|
+
const clientId = this.#baseClient.clientId;
|
|
78
|
+
const commandCase = command.getCommandCase();
|
|
79
|
+
switch (commandCase) {
|
|
80
|
+
case TelemetryCommand.CommandCase.SETTINGS:
|
|
81
|
+
this.#logger.info('Receive settings from remote, endpoints=%s, clientId=%s',
|
|
82
|
+
endpoints, clientId);
|
|
83
|
+
this.#baseClient.onSettingsCommand(endpoints, command.getSettings()!);
|
|
84
|
+
break;
|
|
85
|
+
case TelemetryCommand.CommandCase.RECOVER_ORPHANED_TRANSACTION_COMMAND: {
|
|
86
|
+
this.#logger.info('Receive orphaned transaction recovery command from remote, endpoints=%s, clientId=%s',
|
|
87
|
+
endpoints, clientId);
|
|
88
|
+
this.#baseClient.onRecoverOrphanedTransactionCommand(endpoints, command.getRecoverOrphanedTransactionCommand()!);
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
case TelemetryCommand.CommandCase.VERIFY_MESSAGE_COMMAND: {
|
|
92
|
+
this.#logger.info('Receive message verification command from remote, endpoints=%s, clientId=%s',
|
|
93
|
+
endpoints, clientId);
|
|
94
|
+
this.#baseClient.onVerifyMessageCommand(endpoints, command.getVerifyMessageCommand()!);
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
case TelemetryCommand.CommandCase.PRINT_THREAD_STACK_TRACE_COMMAND: {
|
|
98
|
+
this.#logger.info('Receive thread stack print command from remote, endpoints=%s, clientId=%s',
|
|
99
|
+
endpoints, clientId);
|
|
100
|
+
this.#baseClient.onPrintThreadStackTraceCommand(endpoints, command.getPrintThreadStackTraceCommand()!);
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
default: {
|
|
104
|
+
const commandObj = command.toObject();
|
|
105
|
+
this.#logger.warn('Receive unrecognized command from remote, endpoints=%s, commandCase=%j, command=%j, clientId=%s',
|
|
106
|
+
endpoints, commandCase, commandObj, clientId);
|
|
107
|
+
// should telemetry session start fail
|
|
108
|
+
this.#baseClient.onUnknownCommand(endpoints, commandObj.status!);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
#onError(err: Error) {
|
|
114
|
+
this.#logger.error('Exception raised from stream response observer, endpoints=%s, clientId=%s, error=%s',
|
|
115
|
+
this.#endpoints, this.#baseClient.clientId, err);
|
|
116
|
+
this.release();
|
|
117
|
+
setTimeout(() => {
|
|
118
|
+
this.#renewStream(false);
|
|
119
|
+
}, 1000);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
#onEnd() {
|
|
123
|
+
this.#logger.info('Receive completion for stream response observer, endpoints=%s, clientId=%s',
|
|
124
|
+
this.#endpoints, this.#baseClient.clientId);
|
|
125
|
+
this.release();
|
|
126
|
+
setTimeout(() => {
|
|
127
|
+
this.#renewStream(false);
|
|
128
|
+
}, 1000);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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 os from 'node:os';
|
|
19
|
+
import path from 'node:path';
|
|
20
|
+
import { readFileSync } from 'node:fs';
|
|
21
|
+
import { UA, Language } from '../../proto/apache/rocketmq/v2/definition_pb';
|
|
22
|
+
|
|
23
|
+
const VERSION: string = JSON.parse(readFileSync(path.join(__dirname, '../../package.json'), 'utf-8')).version;
|
|
24
|
+
|
|
25
|
+
export class UserAgent {
|
|
26
|
+
static readonly INSTANCE = new UserAgent(VERSION, os.platform(), os.hostname());
|
|
27
|
+
|
|
28
|
+
readonly version: string;
|
|
29
|
+
readonly platform: string;
|
|
30
|
+
readonly hostname: string;
|
|
31
|
+
|
|
32
|
+
constructor(version: string, platform: string, hostname: string) {
|
|
33
|
+
this.version = version;
|
|
34
|
+
this.platform = platform;
|
|
35
|
+
this.hostname = hostname;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
toProtobuf() {
|
|
39
|
+
return new UA()
|
|
40
|
+
.setLanguage(Language.NODE_JS)
|
|
41
|
+
.setVersion(this.version)
|
|
42
|
+
.setPlatform(this.platform)
|
|
43
|
+
.setHostname(this.hostname);
|
|
44
|
+
}
|
|
45
|
+
}
|