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,153 @@
|
|
|
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 } from '../../proto/apache/rocketmq/v2/definition_pb';
|
|
19
|
+
import { HeartbeatRequest, NotifyClientTerminationRequest } from '../../proto/apache/rocketmq/v2/service_pb';
|
|
20
|
+
import { MessageView } from '../message';
|
|
21
|
+
import { TopicRouteData } from '../route';
|
|
22
|
+
import { createResource } from '../util';
|
|
23
|
+
import { FilterExpression } from './FilterExpression';
|
|
24
|
+
import { SimpleSubscriptionSettings } from './SimpleSubscriptionSettings';
|
|
25
|
+
import { SubscriptionLoadBalancer } from './SubscriptionLoadBalancer';
|
|
26
|
+
import { Consumer, ConsumerOptions } from './Consumer';
|
|
27
|
+
|
|
28
|
+
const RANDOM_INDEX = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
|
|
29
|
+
|
|
30
|
+
export interface SimpleConsumerOptions extends ConsumerOptions {
|
|
31
|
+
/**
|
|
32
|
+
* support tag string as filter, e.g.:
|
|
33
|
+
* ```ts
|
|
34
|
+
* new Map()
|
|
35
|
+
* .set('TestTopic1', 'TestTag1')
|
|
36
|
+
* .set('TestTopic2', 'TestTag2')
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
subscriptions: Map<string/* topic */, FilterExpression | string>;
|
|
40
|
+
/**
|
|
41
|
+
* set await duration for long-polling, default is 30000ms
|
|
42
|
+
*/
|
|
43
|
+
awaitDuration?: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export class SimpleConsumer extends Consumer {
|
|
47
|
+
readonly #simpleSubscriptionSettings: SimpleSubscriptionSettings;
|
|
48
|
+
readonly #subscriptionExpressions = new Map<string, FilterExpression>();
|
|
49
|
+
readonly #subscriptionRouteDataCache = new Map<string, SubscriptionLoadBalancer>();
|
|
50
|
+
readonly #awaitDuration: number;
|
|
51
|
+
#topicIndex = RANDOM_INDEX;
|
|
52
|
+
|
|
53
|
+
constructor(options: SimpleConsumerOptions) {
|
|
54
|
+
options.topics = Array.from(options.subscriptions.keys());
|
|
55
|
+
super(options);
|
|
56
|
+
for (const [ topic, filter ] of options.subscriptions.entries()) {
|
|
57
|
+
if (typeof filter === 'string') {
|
|
58
|
+
// filter is tag string
|
|
59
|
+
this.#subscriptionExpressions.set(topic, new FilterExpression(filter));
|
|
60
|
+
} else {
|
|
61
|
+
this.#subscriptionExpressions.set(topic, filter);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
this.#awaitDuration = options.awaitDuration ?? 30000;
|
|
65
|
+
this.#simpleSubscriptionSettings = new SimpleSubscriptionSettings(options.namespace, this.clientId, this.endpoints,
|
|
66
|
+
this.consumerGroup, this.requestTimeout, this.#awaitDuration, this.#subscriptionExpressions);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
protected getSettings() {
|
|
70
|
+
return this.#simpleSubscriptionSettings;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
protected wrapHeartbeatRequest() {
|
|
74
|
+
return new HeartbeatRequest()
|
|
75
|
+
.setClientType(ClientType.SIMPLE_CONSUMER)
|
|
76
|
+
.setGroup(createResource(this.consumerGroup));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
protected wrapNotifyClientTerminationRequest() {
|
|
80
|
+
return new NotifyClientTerminationRequest()
|
|
81
|
+
.setGroup(createResource(this.consumerGroup));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
protected onTopicRouteDataUpdate(topic: string, topicRouteData: TopicRouteData) {
|
|
85
|
+
this.#updateSubscriptionLoadBalancer(topic, topicRouteData);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
#updateSubscriptionLoadBalancer(topic: string, topicRouteData: TopicRouteData) {
|
|
89
|
+
let subscriptionLoadBalancer = this.#subscriptionRouteDataCache.get(topic);
|
|
90
|
+
if (!subscriptionLoadBalancer) {
|
|
91
|
+
subscriptionLoadBalancer = new SubscriptionLoadBalancer(topicRouteData);
|
|
92
|
+
} else {
|
|
93
|
+
subscriptionLoadBalancer = subscriptionLoadBalancer.update(topicRouteData);
|
|
94
|
+
}
|
|
95
|
+
this.#subscriptionRouteDataCache.set(topic, subscriptionLoadBalancer);
|
|
96
|
+
return subscriptionLoadBalancer;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async #getSubscriptionLoadBalancer(topic: string) {
|
|
100
|
+
let loadBalancer = this.#subscriptionRouteDataCache.get(topic);
|
|
101
|
+
if (!loadBalancer) {
|
|
102
|
+
const topicRouteData = await this.getRouteData(topic);
|
|
103
|
+
loadBalancer = this.#updateSubscriptionLoadBalancer(topic, topicRouteData);
|
|
104
|
+
}
|
|
105
|
+
return loadBalancer;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async subscribe(topic: string, filterExpression: FilterExpression) {
|
|
109
|
+
await this.getRouteData(topic);
|
|
110
|
+
this.#subscriptionExpressions.set(topic, filterExpression);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
unsubscribe(topic: string) {
|
|
114
|
+
this.#subscriptionExpressions.delete(topic);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async receive(maxMessageNum = 10, invisibleDuration = 15000) {
|
|
118
|
+
if (maxMessageNum <= 0) {
|
|
119
|
+
throw new Error(`maxMessageNum must be greater than 0, but got ${maxMessageNum}`);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const topic = this.#nextTopic();
|
|
123
|
+
const filterExpression = this.#subscriptionExpressions.get(topic);
|
|
124
|
+
if (!filterExpression) {
|
|
125
|
+
throw new Error(`No subscription found for topic=${topic}, please subscribe first`);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const loadBalancer = await this.#getSubscriptionLoadBalancer(topic);
|
|
129
|
+
const mq = loadBalancer.takeMessageQueue();
|
|
130
|
+
const request = this.wrapReceiveMessageRequest(maxMessageNum, mq, filterExpression,
|
|
131
|
+
invisibleDuration, this.#awaitDuration);
|
|
132
|
+
return await this.receiveMessage(request, mq, this.#awaitDuration);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async ack(message: MessageView) {
|
|
136
|
+
await this.ackMessage(message);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async changeInvisibleDuration(message: MessageView, invisibleDuration: number) {
|
|
140
|
+
const response = await this.invisibleDuration(message, invisibleDuration);
|
|
141
|
+
// Refresh receipt handle manually
|
|
142
|
+
(message as any).receiptHandle = response;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
#nextTopic() {
|
|
146
|
+
const topics = Array.from(this.#subscriptionExpressions.keys());
|
|
147
|
+
if (topics.length === 0) {
|
|
148
|
+
throw new Error('No subscriptions available to receive messages');
|
|
149
|
+
}
|
|
150
|
+
const index = Math.abs(this.#topicIndex++ % topics.length);
|
|
151
|
+
return topics[index];
|
|
152
|
+
}
|
|
153
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
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 {
|
|
19
|
+
Settings as SettingsPB,
|
|
20
|
+
ClientType,
|
|
21
|
+
Subscription,
|
|
22
|
+
} from '../../proto/apache/rocketmq/v2/definition_pb';
|
|
23
|
+
import { Endpoints } from '../route';
|
|
24
|
+
import { Settings, UserAgent } from '../client';
|
|
25
|
+
import { createDuration, createResource } from '../util';
|
|
26
|
+
import { FilterExpression } from './FilterExpression';
|
|
27
|
+
|
|
28
|
+
export class SimpleSubscriptionSettings extends Settings {
|
|
29
|
+
readonly longPollingTimeout: number;
|
|
30
|
+
readonly group: string;
|
|
31
|
+
readonly subscriptionExpressions: Map<string, FilterExpression>;
|
|
32
|
+
|
|
33
|
+
constructor(namespace: string, clientId: string, accessPoint: Endpoints, group: string, requestTimeout: number, longPollingTimeout: number, subscriptionExpressions: Map<string, FilterExpression>) {
|
|
34
|
+
super(namespace, clientId, ClientType.SIMPLE_CONSUMER, accessPoint, requestTimeout);
|
|
35
|
+
this.longPollingTimeout = longPollingTimeout;
|
|
36
|
+
this.group = group;
|
|
37
|
+
this.subscriptionExpressions = subscriptionExpressions;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
toProtobuf(): SettingsPB {
|
|
41
|
+
const subscription = new Subscription()
|
|
42
|
+
.setGroup(createResource(this.group))
|
|
43
|
+
.setLongPollingTimeout(createDuration(this.longPollingTimeout));
|
|
44
|
+
|
|
45
|
+
for (const [ topic, filterExpression ] of this.subscriptionExpressions.entries()) {
|
|
46
|
+
subscription.addSubscriptions()
|
|
47
|
+
.setTopic(createResource(topic))
|
|
48
|
+
.setExpression(filterExpression.toProtobuf());
|
|
49
|
+
}
|
|
50
|
+
return new SettingsPB()
|
|
51
|
+
.setClientType(this.clientType)
|
|
52
|
+
.setAccessPoint(this.accessPoint.toProtobuf())
|
|
53
|
+
.setRequestTimeout(createDuration(this.requestTimeout))
|
|
54
|
+
.setSubscription(subscription)
|
|
55
|
+
.setUserAgent(UserAgent.INSTANCE.toProtobuf());
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
sync(settings: SettingsPB): void {
|
|
59
|
+
if (settings.getPubSubCase() !== SettingsPB.PubSubCase.SUBSCRIPTION) {
|
|
60
|
+
// log.error("[Bug] Issued settings not match with the client type, clientId={}, pubSubCase={}, "
|
|
61
|
+
// + "clientType={}", clientId, pubSubCase, clientType);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
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 { MessageView } from '../message';
|
|
19
|
+
import { ConsumeService } from './ConsumeService';
|
|
20
|
+
import { MessageListener } from './MessageListener';
|
|
21
|
+
import type { ProcessQueue } from './ProcessQueue';
|
|
22
|
+
|
|
23
|
+
export class StandardConsumeService extends ConsumeService {
|
|
24
|
+
constructor(clientId: string, messageListener: MessageListener) {
|
|
25
|
+
super(clientId, messageListener);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
consume(pq: ProcessQueue, messageViews: MessageView[]): void {
|
|
29
|
+
for (const messageView of messageViews) {
|
|
30
|
+
if (messageView.corrupted) {
|
|
31
|
+
pq.discardMessage(messageView);
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
this.consumeMessage(messageView)
|
|
36
|
+
.then(result => {
|
|
37
|
+
pq.eraseMessage(messageView, result);
|
|
38
|
+
})
|
|
39
|
+
.catch(() => {
|
|
40
|
+
// Should never reach here.
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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 { randomInt } from 'node:crypto';
|
|
19
|
+
import { Permission } from '../../proto/apache/rocketmq/v2/definition_pb';
|
|
20
|
+
import { MessageQueue, TopicRouteData } from '../route';
|
|
21
|
+
import { MASTER_BROKER_ID } from '../util';
|
|
22
|
+
|
|
23
|
+
export class SubscriptionLoadBalancer {
|
|
24
|
+
#index: number;
|
|
25
|
+
#messageQueues: MessageQueue[];
|
|
26
|
+
|
|
27
|
+
constructor(topicRouteData: TopicRouteData, index?: number) {
|
|
28
|
+
this.#messageQueues = topicRouteData.messageQueues.filter(mq => {
|
|
29
|
+
return mq.queueId === MASTER_BROKER_ID && (mq.permission === Permission.READ || mq.permission === Permission.READ_WRITE);
|
|
30
|
+
});
|
|
31
|
+
this.#index = index === undefined ? randomInt(this.#messageQueues.length) : index;
|
|
32
|
+
if (this.#messageQueues.length === 0) {
|
|
33
|
+
throw new Error(`No readable message queue found, topicRouteData=${JSON.stringify(topicRouteData)}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
update(topicRouteData: TopicRouteData) {
|
|
38
|
+
return new SubscriptionLoadBalancer(topicRouteData, this.#index);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
takeMessageQueue() {
|
|
42
|
+
if (this.#index >= this.#messageQueues.length) {
|
|
43
|
+
this.#index = 0;
|
|
44
|
+
}
|
|
45
|
+
return this.#messageQueues[this.#index++];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
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 './FilterExpression';
|
|
20
|
+
export * from './SimpleConsumer';
|
|
21
|
+
export * from './SimpleSubscriptionSettings';
|
|
22
|
+
export * from './SubscriptionLoadBalancer';
|
|
23
|
+
export * from './ConsumeResult';
|
|
24
|
+
export * from './MessageListener';
|
|
25
|
+
export * from './Assignment';
|
|
26
|
+
export * from './Assignments';
|
|
27
|
+
export * from './PushSubscriptionSettings';
|
|
28
|
+
export * from './ConsumeTask';
|
|
29
|
+
export * from './ConsumeService';
|
|
30
|
+
export * from './StandardConsumeService';
|
|
31
|
+
export * from './FifoConsumeService';
|
|
32
|
+
export * from './ProcessQueue';
|
|
33
|
+
export * from './PushConsumer';
|
|
@@ -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 BadRequestException extends ClientException {
|
|
21
|
+
constructor(code: number, message: string, requestId?: string) {
|
|
22
|
+
super(code, message, requestId);
|
|
23
|
+
this.name = 'BadRequestException';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
const REQUEST_ID_KEY = 'request-id';
|
|
19
|
+
const RESPONSE_CODE_KEY = 'response-code';
|
|
20
|
+
|
|
21
|
+
export class ClientException extends Error {
|
|
22
|
+
code: number;
|
|
23
|
+
|
|
24
|
+
constructor(code: number, message: string, requestId?: string) {
|
|
25
|
+
super(`[${REQUEST_ID_KEY}=${requestId}, ${RESPONSE_CODE_KEY}=${code}] ${message}`);
|
|
26
|
+
this.code = code;
|
|
27
|
+
this.name = 'ClientException';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -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 ForbiddenException extends ClientException {
|
|
21
|
+
constructor(code: number, message: string, requestId?: string) {
|
|
22
|
+
super(code, message, requestId);
|
|
23
|
+
this.name = 'ForbiddenException';
|
|
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 InternalErrorException extends ClientException {
|
|
21
|
+
constructor(code: number, message: string, requestId?: string) {
|
|
22
|
+
super(code, message, requestId);
|
|
23
|
+
this.name = 'InternalErrorException';
|
|
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 NotFoundException extends ClientException {
|
|
21
|
+
constructor(code: number, message: string, requestId?: string) {
|
|
22
|
+
super(code, message, requestId);
|
|
23
|
+
this.name = 'NotFoundException';
|
|
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 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
|
+
}
|