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,25 @@
|
|
|
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 { ClientException } from './ClientException';
|
|
19
|
+
|
|
20
|
+
export class PayloadTooLargeException extends ClientException {
|
|
21
|
+
constructor(code: number, message: string, requestId?: string) {
|
|
22
|
+
super(code, message, requestId);
|
|
23
|
+
this.name = 'PayloadTooLargeException';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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 { ClientException } from './ClientException';
|
|
19
|
+
|
|
20
|
+
export class PaymentRequiredException extends ClientException {
|
|
21
|
+
constructor(code: number, message: string, requestId?: string) {
|
|
22
|
+
super(code, message, requestId);
|
|
23
|
+
this.name = 'PaymentRequiredException';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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 { ClientException } from './ClientException';
|
|
19
|
+
|
|
20
|
+
export class ProxyTimeoutException extends ClientException {
|
|
21
|
+
constructor(code: number, message: string, requestId?: string) {
|
|
22
|
+
super(code, message, requestId);
|
|
23
|
+
this.name = 'ProxyTimeoutException';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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 { ClientException } from './ClientException';
|
|
19
|
+
|
|
20
|
+
export class RequestHeaderFieldsTooLargeException extends ClientException {
|
|
21
|
+
constructor(code: number, message: string, requestId?: string) {
|
|
22
|
+
super(code, message, requestId);
|
|
23
|
+
this.name = 'RequestHeaderFieldsTooLargeException';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
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 { Status, Code } from '../../proto/apache/rocketmq/v2/definition_pb';
|
|
19
|
+
import { BadRequestException } from './BadRequestException';
|
|
20
|
+
import { ForbiddenException } from './ForbiddenException';
|
|
21
|
+
import { InternalErrorException } from './InternalErrorException';
|
|
22
|
+
import { NotFoundException } from './NotFoundException';
|
|
23
|
+
import { PayloadTooLargeException } from './PayloadTooLargeException';
|
|
24
|
+
import { PaymentRequiredException } from './PaymentRequiredException';
|
|
25
|
+
import { ProxyTimeoutException } from './ProxyTimeoutException';
|
|
26
|
+
import { RequestHeaderFieldsTooLargeException } from './RequestHeaderFieldsTooLargeException';
|
|
27
|
+
import { TooManyRequestsException } from './TooManyRequestsException';
|
|
28
|
+
import { UnauthorizedException } from './UnauthorizedException';
|
|
29
|
+
import { UnsupportedException } from './UnsupportedException';
|
|
30
|
+
|
|
31
|
+
export class StatusChecker {
|
|
32
|
+
static check(status?: Status.AsObject, requestId?: string) {
|
|
33
|
+
if (!status) return;
|
|
34
|
+
switch (status.code) {
|
|
35
|
+
case Code.OK:
|
|
36
|
+
case Code.MULTIPLE_RESULTS:
|
|
37
|
+
return;
|
|
38
|
+
case Code.BAD_REQUEST:
|
|
39
|
+
case Code.ILLEGAL_ACCESS_POINT:
|
|
40
|
+
case Code.ILLEGAL_TOPIC:
|
|
41
|
+
case Code.ILLEGAL_CONSUMER_GROUP:
|
|
42
|
+
case Code.ILLEGAL_MESSAGE_TAG:
|
|
43
|
+
case Code.ILLEGAL_MESSAGE_KEY:
|
|
44
|
+
case Code.ILLEGAL_MESSAGE_GROUP:
|
|
45
|
+
case Code.ILLEGAL_MESSAGE_PROPERTY_KEY:
|
|
46
|
+
case Code.INVALID_TRANSACTION_ID:
|
|
47
|
+
case Code.ILLEGAL_MESSAGE_ID:
|
|
48
|
+
case Code.ILLEGAL_FILTER_EXPRESSION:
|
|
49
|
+
case Code.ILLEGAL_INVISIBLE_TIME:
|
|
50
|
+
case Code.ILLEGAL_DELIVERY_TIME:
|
|
51
|
+
case Code.INVALID_RECEIPT_HANDLE:
|
|
52
|
+
case Code.MESSAGE_PROPERTY_CONFLICT_WITH_TYPE:
|
|
53
|
+
case Code.UNRECOGNIZED_CLIENT_TYPE:
|
|
54
|
+
case Code.MESSAGE_CORRUPTED:
|
|
55
|
+
case Code.CLIENT_ID_REQUIRED:
|
|
56
|
+
case Code.ILLEGAL_POLLING_TIME:
|
|
57
|
+
throw new BadRequestException(status.code, status.message, requestId);
|
|
58
|
+
case Code.UNAUTHORIZED:
|
|
59
|
+
throw new UnauthorizedException(status.code, status.message, requestId);
|
|
60
|
+
case Code.PAYMENT_REQUIRED:
|
|
61
|
+
throw new PaymentRequiredException(status.code, status.message, requestId);
|
|
62
|
+
case Code.FORBIDDEN:
|
|
63
|
+
throw new ForbiddenException(status.code, status.message, requestId);
|
|
64
|
+
case Code.MESSAGE_NOT_FOUND:
|
|
65
|
+
return;
|
|
66
|
+
case Code.NOT_FOUND:
|
|
67
|
+
case Code.TOPIC_NOT_FOUND:
|
|
68
|
+
case Code.CONSUMER_GROUP_NOT_FOUND:
|
|
69
|
+
throw new NotFoundException(status.code, status.message, requestId);
|
|
70
|
+
case Code.PAYLOAD_TOO_LARGE:
|
|
71
|
+
case Code.MESSAGE_BODY_TOO_LARGE:
|
|
72
|
+
throw new PayloadTooLargeException(status.code, status.message, requestId);
|
|
73
|
+
case Code.TOO_MANY_REQUESTS:
|
|
74
|
+
throw new TooManyRequestsException(status.code, status.message, requestId);
|
|
75
|
+
case Code.REQUEST_HEADER_FIELDS_TOO_LARGE:
|
|
76
|
+
case Code.MESSAGE_PROPERTIES_TOO_LARGE:
|
|
77
|
+
throw new RequestHeaderFieldsTooLargeException(status.code, status.message, requestId);
|
|
78
|
+
case Code.INTERNAL_ERROR:
|
|
79
|
+
case Code.INTERNAL_SERVER_ERROR:
|
|
80
|
+
case Code.HA_NOT_AVAILABLE:
|
|
81
|
+
throw new InternalErrorException(status.code, status.message, requestId);
|
|
82
|
+
case Code.PROXY_TIMEOUT:
|
|
83
|
+
case Code.MASTER_PERSISTENCE_TIMEOUT:
|
|
84
|
+
case Code.SLAVE_PERSISTENCE_TIMEOUT:
|
|
85
|
+
throw new ProxyTimeoutException(status.code, status.message, requestId);
|
|
86
|
+
case Code.UNSUPPORTED:
|
|
87
|
+
case Code.VERSION_UNSUPPORTED:
|
|
88
|
+
case Code.VERIFY_FIFO_MESSAGE_UNSUPPORTED:
|
|
89
|
+
throw new UnsupportedException(status.code, status.message, requestId);
|
|
90
|
+
default:
|
|
91
|
+
throw new UnsupportedException(status.code, status.message, requestId);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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 { ClientException } from './ClientException';
|
|
19
|
+
|
|
20
|
+
export class TooManyRequestsException extends ClientException {
|
|
21
|
+
constructor(code: number, message: string, requestId?: string) {
|
|
22
|
+
super(code, message, requestId);
|
|
23
|
+
this.name = 'TooManyRequestsException';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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 { ClientException } from './ClientException';
|
|
19
|
+
|
|
20
|
+
export class UnauthorizedException extends ClientException {
|
|
21
|
+
constructor(code: number, message: string, requestId?: string) {
|
|
22
|
+
super(code, message, requestId);
|
|
23
|
+
this.name = 'UnauthorizedException';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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 { ClientException } from './ClientException';
|
|
19
|
+
|
|
20
|
+
export class UnsupportedException extends ClientException {
|
|
21
|
+
constructor(code: number, message: string, requestId?: string) {
|
|
22
|
+
super(code, message, requestId);
|
|
23
|
+
this.name = 'UnsupportedException';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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 * from './BadRequestException';
|
|
19
|
+
export * from './ClientException';
|
|
20
|
+
export * from './ForbiddenException';
|
|
21
|
+
export * from './InternalErrorException';
|
|
22
|
+
export * from './NotFoundException';
|
|
23
|
+
export * from './PayloadTooLargeException';
|
|
24
|
+
export * from './PaymentRequiredException';
|
|
25
|
+
export * from './ProxyTimeoutException';
|
|
26
|
+
export * from './RequestHeaderFieldsTooLargeException';
|
|
27
|
+
export * from './StatusChecker';
|
|
28
|
+
export * from './TooManyRequestsException';
|
|
29
|
+
export * from './UnauthorizedException';
|
|
30
|
+
export * from './UnsupportedException';
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 * from './consumer';
|
|
19
|
+
export * from './exception';
|
|
20
|
+
export * from './message';
|
|
21
|
+
export * from './producer';
|
|
22
|
+
export * from './retry';
|
|
23
|
+
export * from './route';
|
|
@@ -0,0 +1,51 @@
|
|
|
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 MessageOptions {
|
|
19
|
+
topic: string;
|
|
20
|
+
body: Buffer;
|
|
21
|
+
tag?: string;
|
|
22
|
+
messageGroup?: string;
|
|
23
|
+
keys?: string[];
|
|
24
|
+
properties?: Map<string, string>;
|
|
25
|
+
delay?: number;
|
|
26
|
+
deliveryTimestamp?: Date;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export class Message {
|
|
30
|
+
topic: string;
|
|
31
|
+
body: Buffer;
|
|
32
|
+
tag?: string;
|
|
33
|
+
messageGroup?: string;
|
|
34
|
+
keys: string[];
|
|
35
|
+
properties?: Map<string, string>;
|
|
36
|
+
deliveryTimestamp?: Date;
|
|
37
|
+
|
|
38
|
+
constructor(options: MessageOptions) {
|
|
39
|
+
this.topic = options.topic;
|
|
40
|
+
this.body = options.body;
|
|
41
|
+
this.tag = options.tag;
|
|
42
|
+
this.messageGroup = options.messageGroup;
|
|
43
|
+
this.keys = options.keys ?? [];
|
|
44
|
+
this.properties = options.properties;
|
|
45
|
+
let deliveryTimestamp = options.deliveryTimestamp;
|
|
46
|
+
if (options.delay && !deliveryTimestamp) {
|
|
47
|
+
deliveryTimestamp = new Date(Date.now() + options.delay);
|
|
48
|
+
}
|
|
49
|
+
this.deliveryTimestamp = deliveryTimestamp;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
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 address from 'address';
|
|
19
|
+
|
|
20
|
+
export enum MESSAGE_VERSION {
|
|
21
|
+
V0 = 0x00,
|
|
22
|
+
V1 = 0x01,
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class MessageId {
|
|
26
|
+
id: string;
|
|
27
|
+
/**
|
|
28
|
+
* e.g.: 0x01: fixed 1 byte for current version
|
|
29
|
+
* offset = 0
|
|
30
|
+
*/
|
|
31
|
+
version: MESSAGE_VERSION;
|
|
32
|
+
/**
|
|
33
|
+
* e.g.: 0x56F7E71C361B: lower 6 bytes of local mac address
|
|
34
|
+
* offset = 1
|
|
35
|
+
*/
|
|
36
|
+
macAddress: string;
|
|
37
|
+
/**
|
|
38
|
+
* e.g.: 0x21BC: lower 2 bytes of process id
|
|
39
|
+
* offset = 7
|
|
40
|
+
*/
|
|
41
|
+
processId: number;
|
|
42
|
+
/**
|
|
43
|
+
* e.g: 0x024CCDBE: seconds since 2021-01-01 00:00:00(UTC+0, lower 4 bytes)
|
|
44
|
+
* offset = 9
|
|
45
|
+
*/
|
|
46
|
+
timestamp: number;
|
|
47
|
+
/**
|
|
48
|
+
* e.g.: 0x00000000: sequence number(4 bytes)
|
|
49
|
+
* offset = 13
|
|
50
|
+
*/
|
|
51
|
+
sequence: number;
|
|
52
|
+
|
|
53
|
+
toString() {
|
|
54
|
+
return this.id;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const MAX_UINT32 = 0xFFFFFFFF;
|
|
59
|
+
const MAX_UINT16 = 0xFFFF;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Message Identifier
|
|
63
|
+
* https://github.com/apache/rocketmq-clients/blob/master/docs/message_id.md
|
|
64
|
+
*/
|
|
65
|
+
export class MessageIdFactory {
|
|
66
|
+
// static #hostname = hostname();
|
|
67
|
+
static #sequence = 0;
|
|
68
|
+
static #buf = Buffer.alloc(1 + 6 + 2 + 4 + 4);
|
|
69
|
+
// 2021-01-01 00:00:00(UTC+0), 1609459200000
|
|
70
|
+
static #sinceTimestamp = new Date('2021-01-01T00:00:00Z').getTime() / 1000;
|
|
71
|
+
// lower 2 bytes of process id
|
|
72
|
+
static #processId = process.pid % MAX_UINT16;
|
|
73
|
+
static MAC = '000000000000';
|
|
74
|
+
|
|
75
|
+
static create() {
|
|
76
|
+
const messageId = new MessageId();
|
|
77
|
+
messageId.version = MESSAGE_VERSION.V1;
|
|
78
|
+
messageId.macAddress = this.MAC;
|
|
79
|
+
messageId.processId = this.#processId;
|
|
80
|
+
messageId.timestamp = this.#getCurrentTimestamp();
|
|
81
|
+
messageId.sequence = this.#sequence++;
|
|
82
|
+
if (this.#sequence > MAX_UINT32) {
|
|
83
|
+
this.#sequence = 0;
|
|
84
|
+
}
|
|
85
|
+
this.#buf.writeUInt8(messageId.version, 0);
|
|
86
|
+
this.#buf.write(messageId.macAddress, 1, 'hex');
|
|
87
|
+
this.#buf.writeUInt16BE(messageId.processId, 7);
|
|
88
|
+
this.#buf.writeUInt32BE(messageId.timestamp, 9);
|
|
89
|
+
this.#buf.writeUInt32BE(messageId.sequence, 13);
|
|
90
|
+
messageId.id = this.#buf.toString('hex').toUpperCase();
|
|
91
|
+
return messageId;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
static decode(id: string) {
|
|
95
|
+
const messageId = new MessageId();
|
|
96
|
+
messageId.id = id;
|
|
97
|
+
this.#buf.write(id, 0, 'hex');
|
|
98
|
+
messageId.version = this.#buf.readUInt8(0);
|
|
99
|
+
messageId.macAddress = this.#buf.subarray(1, 7).toString('hex');
|
|
100
|
+
messageId.processId = this.#buf.readUInt16BE(7);
|
|
101
|
+
messageId.timestamp = this.#buf.readUInt32BE(9);
|
|
102
|
+
messageId.sequence = this.#buf.readUInt32BE(13);
|
|
103
|
+
return messageId;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
static #getCurrentTimestamp() {
|
|
107
|
+
// use lower 4 bytes
|
|
108
|
+
return Math.floor(Date.now() / 1000 - this.#sinceTimestamp) % MAX_UINT32;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// set current mac address
|
|
113
|
+
address.mac((err, mac) => {
|
|
114
|
+
if (err) {
|
|
115
|
+
console.warn('[rocketmq-client-nodejs] can\'t get mac address, %s', err.message);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (!mac) {
|
|
119
|
+
console.warn('[rocketmq-client-nodejs] can\'t get mac address');
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
MessageIdFactory.MAC = mac.replaceAll(':', '');
|
|
123
|
+
});
|
|
@@ -0,0 +1,94 @@
|
|
|
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 { gunzipSync } from 'node:zlib';
|
|
19
|
+
import {
|
|
20
|
+
DigestType,
|
|
21
|
+
Encoding,
|
|
22
|
+
Message as MessagePB,
|
|
23
|
+
} from '../../proto/apache/rocketmq/v2/definition_pb';
|
|
24
|
+
import { crc32CheckSum, md5CheckSum, sha1CheckSum } from '../util';
|
|
25
|
+
import { Endpoints, MessageQueue } from '../route';
|
|
26
|
+
|
|
27
|
+
export class MessageView {
|
|
28
|
+
readonly messageId: string;
|
|
29
|
+
readonly topic: string;
|
|
30
|
+
readonly body: Buffer;
|
|
31
|
+
readonly corrupted: boolean;
|
|
32
|
+
readonly transportDeliveryTimestamp?: Date;
|
|
33
|
+
readonly tag?: string;
|
|
34
|
+
readonly messageGroup?: string;
|
|
35
|
+
readonly deliveryTimestamp?: Date;
|
|
36
|
+
readonly keys: string[];
|
|
37
|
+
readonly bornHost: string;
|
|
38
|
+
readonly bornTimestamp?: Date;
|
|
39
|
+
readonly deliveryAttempt?: number;
|
|
40
|
+
readonly endpoints: Endpoints;
|
|
41
|
+
readonly receiptHandle: string;
|
|
42
|
+
readonly offset?: number;
|
|
43
|
+
readonly decodeTimestamp: Date;
|
|
44
|
+
readonly properties = new Map<string, string>();
|
|
45
|
+
|
|
46
|
+
constructor(message: MessagePB, messageQueue?: MessageQueue, transportDeliveryTimestamp?: Date) {
|
|
47
|
+
const systemProperties = message.getSystemProperties()!;
|
|
48
|
+
const bodyDigest = systemProperties.getBodyDigest()!.toObject();
|
|
49
|
+
const digestType = bodyDigest.type;
|
|
50
|
+
const checksum = bodyDigest.checksum;
|
|
51
|
+
let expectedChecksum = '';
|
|
52
|
+
let bodyBytes = Buffer.from(message.getBody_asU8());
|
|
53
|
+
switch (digestType) {
|
|
54
|
+
case DigestType.CRC32:
|
|
55
|
+
expectedChecksum = crc32CheckSum(bodyBytes);
|
|
56
|
+
break;
|
|
57
|
+
case DigestType.MD5:
|
|
58
|
+
expectedChecksum = md5CheckSum(bodyBytes);
|
|
59
|
+
break;
|
|
60
|
+
case DigestType.SHA1:
|
|
61
|
+
expectedChecksum = sha1CheckSum(bodyBytes);
|
|
62
|
+
break;
|
|
63
|
+
default:
|
|
64
|
+
// log.error("Unsupported message body digest algorithm, digestType={}, topic={}, messageId={}",
|
|
65
|
+
// digestType, topic, messageId);
|
|
66
|
+
}
|
|
67
|
+
if (expectedChecksum && expectedChecksum !== checksum) {
|
|
68
|
+
this.corrupted = true;
|
|
69
|
+
}
|
|
70
|
+
if (systemProperties.getBodyEncoding() === Encoding.GZIP) {
|
|
71
|
+
bodyBytes = gunzipSync(bodyBytes);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
for (const [ key, value ] of message.getUserPropertiesMap().entries()) {
|
|
75
|
+
this.properties.set(key, value);
|
|
76
|
+
}
|
|
77
|
+
this.messageId = systemProperties.getMessageId();
|
|
78
|
+
this.topic = message.getTopic()!.getName();
|
|
79
|
+
this.tag = systemProperties.getTag();
|
|
80
|
+
this.messageGroup = systemProperties.getMessageGroup();
|
|
81
|
+
this.deliveryTimestamp = systemProperties.getDeliveryTimestamp()?.toDate();
|
|
82
|
+
this.keys = systemProperties.getKeysList();
|
|
83
|
+
this.bornHost = systemProperties.getBornHost();
|
|
84
|
+
this.bornTimestamp = systemProperties.getBornTimestamp()?.toDate();
|
|
85
|
+
this.deliveryAttempt = systemProperties.getDeliveryAttempt();
|
|
86
|
+
this.offset = systemProperties.getQueueOffset();
|
|
87
|
+
this.receiptHandle = systemProperties.getReceiptHandle()!;
|
|
88
|
+
this.transportDeliveryTimestamp = transportDeliveryTimestamp;
|
|
89
|
+
if (messageQueue) {
|
|
90
|
+
this.endpoints = messageQueue.broker.endpoints;
|
|
91
|
+
}
|
|
92
|
+
this.body = bodyBytes;
|
|
93
|
+
}
|
|
94
|
+
}
|