rocketmq-client-nodejs 1.0.5 → 1.0.7
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/dist/consumer/ConsumeResult.d.ts +38 -3
- package/dist/consumer/ConsumeResult.js +58 -7
- package/dist/consumer/FifoConsumeService.d.ts +33 -1
- package/dist/consumer/FifoConsumeService.js +72 -87
- package/dist/consumer/LiteFifoConsumeService.d.ts +44 -0
- package/dist/consumer/LiteFifoConsumeService.js +94 -0
- package/dist/consumer/LitePushConsumer.d.ts +14 -0
- package/dist/consumer/LitePushConsumer.js +25 -4
- package/dist/consumer/LitePushConsumerImpl.d.ts +9 -0
- package/dist/consumer/LitePushConsumerImpl.js +30 -1
- package/dist/consumer/LiteStandardConsumeService.d.ts +32 -0
- package/dist/consumer/LiteStandardConsumeService.js +63 -0
- package/dist/consumer/LiteSubscriptionManager.js +3 -1
- package/dist/consumer/ProcessQueue.js +50 -6
- package/dist/consumer/PushConsumer.d.ts +1 -0
- package/dist/consumer/PushConsumer.js +5 -4
- package/dist/consumer/index.d.ts +2 -0
- package/dist/consumer/index.js +3 -1
- package/dist/message/MessageView.d.ts +8 -1
- package/dist/message/MessageView.js +11 -1
- package/package.json +1 -1
- package/proto/apache/rocketmq/v2/definition.proto +1 -1
- package/src/consumer/ConsumeResult.ts +62 -3
- package/src/consumer/FifoConsumeService.ts +78 -93
- package/src/consumer/LiteFifoConsumeService.ts +103 -0
- package/src/consumer/LitePushConsumer.ts +29 -3
- package/src/consumer/LitePushConsumerImpl.ts +36 -0
- package/src/consumer/LiteStandardConsumeService.ts +73 -0
- package/src/consumer/LiteSubscriptionManager.ts +2 -0
- package/src/consumer/ProcessQueue.ts +65 -6
- package/src/consumer/PushConsumer.ts +4 -3
- package/src/consumer/index.ts +2 -0
- package/src/message/MessageView.ts +12 -1
|
@@ -14,7 +14,42 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Consume result for push consumer.
|
|
19
|
+
*
|
|
20
|
+
* <p>Designed for push consumer specifically. This is a class-based result
|
|
21
|
+
* (matching the Java client) so that it can be extended with suspend results.</p>
|
|
22
|
+
*/
|
|
23
|
+
export declare class ConsumeResult {
|
|
24
|
+
/**
|
|
25
|
+
* Consume message successfully.
|
|
26
|
+
*/
|
|
27
|
+
static readonly SUCCESS: ConsumeResult;
|
|
28
|
+
/**
|
|
29
|
+
* Failed to consume message.
|
|
30
|
+
*/
|
|
31
|
+
static readonly FAILURE: ConsumeResult;
|
|
32
|
+
readonly name: string;
|
|
33
|
+
protected constructor(name: string);
|
|
34
|
+
toString(): string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Suspend consume result.
|
|
38
|
+
*
|
|
39
|
+
* <p>When returned by the message listener, the consumer will suspend
|
|
40
|
+
* consumption of the current message (and related messages in FIFO mode)
|
|
41
|
+
* for the specified duration by changing the invisible duration.</p>
|
|
42
|
+
*/
|
|
43
|
+
export declare class ConsumeResultSuspend extends ConsumeResult {
|
|
44
|
+
readonly suspendTimeMs: number;
|
|
45
|
+
private constructor();
|
|
46
|
+
/**
|
|
47
|
+
* Create a suspend result with the given suspend time in milliseconds.
|
|
48
|
+
*
|
|
49
|
+
* @param suspendTimeMs - Suspend time in milliseconds
|
|
50
|
+
* @return {ConsumeResultSuspend} ConsumeResultSuspend instance
|
|
51
|
+
* @throws {Error} if suspendTimeMs is less than 50ms
|
|
52
|
+
*/
|
|
53
|
+
static of(suspendTimeMs: number): ConsumeResultSuspend;
|
|
54
|
+
toString(): string;
|
|
20
55
|
}
|
|
@@ -16,10 +16,61 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.ConsumeResult = void 0;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
exports.ConsumeResultSuspend = exports.ConsumeResult = void 0;
|
|
20
|
+
/**
|
|
21
|
+
* Consume result for push consumer.
|
|
22
|
+
*
|
|
23
|
+
* <p>Designed for push consumer specifically. This is a class-based result
|
|
24
|
+
* (matching the Java client) so that it can be extended with suspend results.</p>
|
|
25
|
+
*/
|
|
26
|
+
class ConsumeResult {
|
|
27
|
+
/**
|
|
28
|
+
* Consume message successfully.
|
|
29
|
+
*/
|
|
30
|
+
static SUCCESS = new ConsumeResult('SUCCESS');
|
|
31
|
+
/**
|
|
32
|
+
* Failed to consume message.
|
|
33
|
+
*/
|
|
34
|
+
static FAILURE = new ConsumeResult('FAILURE');
|
|
35
|
+
name;
|
|
36
|
+
constructor(name) {
|
|
37
|
+
this.name = name;
|
|
38
|
+
}
|
|
39
|
+
toString() {
|
|
40
|
+
return this.name;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.ConsumeResult = ConsumeResult;
|
|
44
|
+
const MIN_SUSPEND_TIME_MS = 50;
|
|
45
|
+
/**
|
|
46
|
+
* Suspend consume result.
|
|
47
|
+
*
|
|
48
|
+
* <p>When returned by the message listener, the consumer will suspend
|
|
49
|
+
* consumption of the current message (and related messages in FIFO mode)
|
|
50
|
+
* for the specified duration by changing the invisible duration.</p>
|
|
51
|
+
*/
|
|
52
|
+
class ConsumeResultSuspend extends ConsumeResult {
|
|
53
|
+
suspendTimeMs;
|
|
54
|
+
constructor(suspendTimeMs) {
|
|
55
|
+
super('SUSPEND');
|
|
56
|
+
if (suspendTimeMs < MIN_SUSPEND_TIME_MS) {
|
|
57
|
+
throw new Error(`suspend time cannot be less than ${MIN_SUSPEND_TIME_MS}ms, got ${suspendTimeMs}ms`);
|
|
58
|
+
}
|
|
59
|
+
this.suspendTimeMs = suspendTimeMs;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Create a suspend result with the given suspend time in milliseconds.
|
|
63
|
+
*
|
|
64
|
+
* @param suspendTimeMs - Suspend time in milliseconds
|
|
65
|
+
* @return {ConsumeResultSuspend} ConsumeResultSuspend instance
|
|
66
|
+
* @throws {Error} if suspendTimeMs is less than 50ms
|
|
67
|
+
*/
|
|
68
|
+
static of(suspendTimeMs) {
|
|
69
|
+
return new ConsumeResultSuspend(suspendTimeMs);
|
|
70
|
+
}
|
|
71
|
+
toString() {
|
|
72
|
+
return `SUSPEND(${this.suspendTimeMs}ms)`;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.ConsumeResultSuspend = ConsumeResultSuspend;
|
|
76
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ29uc3VtZVJlc3VsdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jb25zdW1lci9Db25zdW1lUmVzdWx0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQTs7Ozs7Ozs7Ozs7Ozs7O0dBZUc7OztBQUVIOzs7OztHQUtHO0FBQ0gsTUFBYSxhQUFhO0lBQ3hCOztPQUVHO0lBQ0gsTUFBTSxDQUFVLE9BQU8sR0FBRyxJQUFJLGFBQWEsQ0FBQyxTQUFTLENBQUMsQ0FBQztJQUV2RDs7T0FFRztJQUNILE1BQU0sQ0FBVSxPQUFPLEdBQUcsSUFBSSxhQUFhLENBQUMsU0FBUyxDQUFDLENBQUM7SUFFOUMsSUFBSSxDQUFTO0lBRXRCLFlBQXNCLElBQVk7UUFDaEMsSUFBSSxDQUFDLElBQUksR0FBRyxJQUFJLENBQUM7SUFDbkIsQ0FBQztJQUVELFFBQVE7UUFDTixPQUFPLElBQUksQ0FBQyxJQUFJLENBQUM7SUFDbkIsQ0FBQzs7QUFuQkgsc0NBb0JDO0FBRUQsTUFBTSxtQkFBbUIsR0FBRyxFQUFFLENBQUM7QUFFL0I7Ozs7OztHQU1HO0FBQ0gsTUFBYSxvQkFBcUIsU0FBUSxhQUFhO0lBQzVDLGFBQWEsQ0FBUztJQUUvQixZQUFvQixhQUFxQjtRQUN2QyxLQUFLLENBQUMsU0FBUyxDQUFDLENBQUM7UUFDakIsSUFBSSxhQUFhLEdBQUcsbUJBQW1CLEVBQUUsQ0FBQztZQUN4QyxNQUFNLElBQUksS0FBSyxDQUFDLG9DQUFvQyxtQkFBbUIsV0FBVyxhQUFhLElBQUksQ0FBQyxDQUFDO1FBQ3ZHLENBQUM7UUFDRCxJQUFJLENBQUMsYUFBYSxHQUFHLGFBQWEsQ0FBQztJQUNyQyxDQUFDO0lBRUQ7Ozs7OztPQU1HO0lBQ0gsTUFBTSxDQUFDLEVBQUUsQ0FBQyxhQUFxQjtRQUM3QixPQUFPLElBQUksb0JBQW9CLENBQUMsYUFBYSxDQUFDLENBQUM7SUFDakQsQ0FBQztJQUVELFFBQVE7UUFDTixPQUFPLFdBQVcsSUFBSSxDQUFDLGFBQWEsS0FBSyxDQUFDO0lBQzVDLENBQUM7Q0FDRjtBQXpCRCxvREF5QkMifQ==
|
|
@@ -20,6 +20,38 @@ import { MessageListener } from './MessageListener';
|
|
|
20
20
|
import type { ProcessQueue } from './ProcessQueue';
|
|
21
21
|
export declare class FifoConsumeService extends ConsumeService {
|
|
22
22
|
#private;
|
|
23
|
-
constructor(clientId: string, messageListener: MessageListener,
|
|
23
|
+
constructor(clientId: string, messageListener: MessageListener, enableFifoConsumeAccelerator?: boolean);
|
|
24
24
|
consume(pq: ProcessQueue, messageViews: MessageView[]): void;
|
|
25
|
+
/**
|
|
26
|
+
* Get the group key for the given message view.
|
|
27
|
+
* Subclasses can override this method to provide different grouping logic.
|
|
28
|
+
*
|
|
29
|
+
* @param messageView - The message view
|
|
30
|
+
* @return {string} The group key, empty string means no grouping
|
|
31
|
+
*/
|
|
32
|
+
protected getMessageGroupKey(messageView: MessageView): string;
|
|
33
|
+
/**
|
|
34
|
+
* Consume messages iteratively using the provided message view array.
|
|
35
|
+
* This method handles corrupted messages and continues processing the next valid message.
|
|
36
|
+
*
|
|
37
|
+
* @param pq - The process queue
|
|
38
|
+
* @param messageViews - The message views to consume
|
|
39
|
+
* @param startIndex - The index to start consuming from
|
|
40
|
+
* @return {Promise<void>} Promise that resolves when all messages are consumed
|
|
41
|
+
*/
|
|
42
|
+
protected consumeIteratively(pq: ProcessQueue, messageViews: MessageView[], startIndex: number): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Get the next valid message from the message view array.
|
|
45
|
+
* Skip corrupted messages and return the first valid one.
|
|
46
|
+
* Returns null if there are no more messages.
|
|
47
|
+
*
|
|
48
|
+
* @param pq - The process queue
|
|
49
|
+
* @param messageViews - The message views
|
|
50
|
+
* @param startIndex - The index to start searching from
|
|
51
|
+
* @return {{ messageView: MessageView; nextIndex: number } | null} The next valid message and the index after it, or null
|
|
52
|
+
*/
|
|
53
|
+
protected getNextValidMessage(pq: ProcessQueue, messageViews: MessageView[], startIndex: number): {
|
|
54
|
+
messageView: MessageView;
|
|
55
|
+
nextIndex: number;
|
|
56
|
+
} | null;
|
|
25
57
|
}
|
|
@@ -20,111 +20,96 @@ exports.FifoConsumeService = void 0;
|
|
|
20
20
|
const ConsumeService_1 = require("./ConsumeService");
|
|
21
21
|
const Logger_1 = require("../client/Logger");
|
|
22
22
|
class FifoConsumeService extends ConsumeService_1.ConsumeService {
|
|
23
|
-
#
|
|
24
|
-
#groupProcessing = new Map();
|
|
23
|
+
#enableFifoConsumeAccelerator;
|
|
25
24
|
#logger;
|
|
26
|
-
constructor(clientId, messageListener,
|
|
25
|
+
constructor(clientId, messageListener, enableFifoConsumeAccelerator) {
|
|
27
26
|
super(clientId, messageListener);
|
|
28
|
-
this.#
|
|
27
|
+
this.#enableFifoConsumeAccelerator = enableFifoConsumeAccelerator ?? false;
|
|
29
28
|
this.#logger = (0, Logger_1.getDefaultLogger)();
|
|
30
29
|
}
|
|
31
30
|
consume(pq, messageViews) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
this.#consumeIteratively(pq, messageViews, 0);
|
|
31
|
+
if (!pq || !messageViews) {
|
|
32
|
+
this.#logger.error('[Bug] Invalid arguments for consume, pq=%s, messageViews=%s, clientId=%s', pq, messageViews, this.clientId);
|
|
35
33
|
return;
|
|
36
34
|
}
|
|
37
|
-
this.#
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
#consumeWithAccelerator(pq, messageViews) {
|
|
46
|
-
// Group messages by messageGroup
|
|
47
|
-
const groupedMessages = new Map();
|
|
48
|
-
const ungroupedMessages = [];
|
|
35
|
+
if (!this.#enableFifoConsumeAccelerator || messageViews.length <= 1) {
|
|
36
|
+
this.consumeIteratively(pq, messageViews, 0).catch(() => {
|
|
37
|
+
// Error already logged, ignore
|
|
38
|
+
});
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
// Group messages by group key. Default to null-key group for unkeyed messages.
|
|
42
|
+
const messageViewsGroupByGroupKey = new Map();
|
|
49
43
|
for (const messageView of messageViews) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (messageGroup) {
|
|
56
|
-
const group = groupedMessages.get(messageGroup) || [];
|
|
57
|
-
group.push(messageView);
|
|
58
|
-
groupedMessages.set(messageGroup, group);
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
ungroupedMessages.push(messageView);
|
|
44
|
+
const groupKey = this.getMessageGroupKey(messageView);
|
|
45
|
+
let group = messageViewsGroupByGroupKey.get(groupKey);
|
|
46
|
+
if (!group) {
|
|
47
|
+
group = [];
|
|
48
|
+
messageViewsGroupByGroupKey.set(groupKey, group);
|
|
62
49
|
}
|
|
50
|
+
group.push(messageView);
|
|
63
51
|
}
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
for (const [, messages] of groupedMessages.entries()) {
|
|
69
|
-
this.#processMessageGroup(pq, messages);
|
|
70
|
-
}
|
|
71
|
-
// Process ungrouped messages in parallel
|
|
72
|
-
for (const messageView of ungroupedMessages) {
|
|
73
|
-
this.consumeMessage(messageView)
|
|
74
|
-
.then(result => pq.eraseFifoMessage(messageView, result))
|
|
75
|
-
.catch(() => {
|
|
76
|
-
// Error already logged, continue with next message
|
|
52
|
+
this.#logger.debug?.('FifoConsumeService parallel consume, messageViewsNum=%d, groupNum=%d', messageViews.length, messageViewsGroupByGroupKey.size);
|
|
53
|
+
for (const list of messageViewsGroupByGroupKey.values()) {
|
|
54
|
+
this.consumeIteratively(pq, list, 0).catch(() => {
|
|
55
|
+
// Error already logged, ignore
|
|
77
56
|
});
|
|
78
57
|
}
|
|
79
58
|
}
|
|
80
59
|
/**
|
|
81
|
-
*
|
|
60
|
+
* Get the group key for the given message view.
|
|
61
|
+
* Subclasses can override this method to provide different grouping logic.
|
|
62
|
+
*
|
|
63
|
+
* @param messageView - The message view
|
|
64
|
+
* @return {string} The group key, empty string means no grouping
|
|
82
65
|
*/
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const messageGroup = messages[0]?.messageGroup || 'NO_GROUP';
|
|
86
|
-
const existingPromise = this.#groupProcessing.get(messageGroup);
|
|
87
|
-
const processTask = (async () => {
|
|
88
|
-
// Wait for previous processing to complete if any
|
|
89
|
-
if (existingPromise) {
|
|
90
|
-
await existingPromise.catch(() => {
|
|
91
|
-
// Ignore previous errors, continue processing
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
// Process messages in sequence
|
|
95
|
-
for (const messageView of messages) {
|
|
96
|
-
try {
|
|
97
|
-
const result = await this.consumeMessage(messageView);
|
|
98
|
-
await pq.eraseFifoMessage(messageView, result);
|
|
99
|
-
}
|
|
100
|
-
catch (error) {
|
|
101
|
-
this.#logger.error('Failed to process FIFO message, messageGroup=%s, messageId=%s, error=%s', messageGroup, messageView.messageId, error);
|
|
102
|
-
// Continue with next message even if current fails
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
})();
|
|
106
|
-
// Store the promise for this group
|
|
107
|
-
this.#groupProcessing.set(messageGroup, processTask);
|
|
108
|
-
// Clean up when done
|
|
109
|
-
processTask.finally(() => {
|
|
110
|
-
this.#groupProcessing.delete(messageGroup);
|
|
111
|
-
});
|
|
66
|
+
getMessageGroupKey(messageView) {
|
|
67
|
+
return messageView.messageGroup || '';
|
|
112
68
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Consume messages iteratively using the provided message view array.
|
|
71
|
+
* This method handles corrupted messages and continues processing the next valid message.
|
|
72
|
+
*
|
|
73
|
+
* @param pq - The process queue
|
|
74
|
+
* @param messageViews - The message views to consume
|
|
75
|
+
* @param startIndex - The index to start consuming from
|
|
76
|
+
* @return {Promise<void>} Promise that resolves when all messages are consumed
|
|
77
|
+
*/
|
|
78
|
+
consumeIteratively(pq, messageViews, startIndex) {
|
|
79
|
+
const next = this.getNextValidMessage(pq, messageViews, startIndex);
|
|
80
|
+
if (!next) {
|
|
81
|
+
return Promise.resolve();
|
|
122
82
|
}
|
|
123
|
-
|
|
83
|
+
const { messageView, nextIndex } = next;
|
|
84
|
+
return this.consumeMessage(messageView)
|
|
124
85
|
.then(result => pq.eraseFifoMessage(messageView, result))
|
|
125
|
-
.then(() => this
|
|
126
|
-
.catch(() => this
|
|
86
|
+
.then(() => this.consumeIteratively(pq, messageViews, nextIndex))
|
|
87
|
+
.catch(() => this.consumeIteratively(pq, messageViews, nextIndex));
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Get the next valid message from the message view array.
|
|
91
|
+
* Skip corrupted messages and return the first valid one.
|
|
92
|
+
* Returns null if there are no more messages.
|
|
93
|
+
*
|
|
94
|
+
* @param pq - The process queue
|
|
95
|
+
* @param messageViews - The message views
|
|
96
|
+
* @param startIndex - The index to start searching from
|
|
97
|
+
* @return {{ messageView: MessageView; nextIndex: number } | null} The next valid message and the index after it, or null
|
|
98
|
+
*/
|
|
99
|
+
getNextValidMessage(pq, messageViews, startIndex) {
|
|
100
|
+
for (let i = startIndex; i < messageViews.length; i++) {
|
|
101
|
+
const messageView = messageViews[i];
|
|
102
|
+
if (messageView.corrupted) {
|
|
103
|
+
// Discard corrupted message.
|
|
104
|
+
this.#logger.error('Message is corrupted for FIFO consumption, prepare to discard it, mq=%s, '
|
|
105
|
+
+ 'messageId=%s, clientId=%s', pq.getMessageQueue(), messageView.messageId, this.clientId);
|
|
106
|
+
pq.discardFifoMessage(messageView);
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
return { messageView, nextIndex: i + 1 };
|
|
110
|
+
}
|
|
111
|
+
return null;
|
|
127
112
|
}
|
|
128
113
|
}
|
|
129
114
|
exports.FifoConsumeService = FifoConsumeService;
|
|
130
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
115
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRmlmb0NvbnN1bWVTZXJ2aWNlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2NvbnN1bWVyL0ZpZm9Db25zdW1lU2VydmljZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7Ozs7Ozs7Ozs7Ozs7OztHQWVHOzs7QUFHSCxxREFBa0Q7QUFHbEQsNkNBQTZEO0FBRTdELE1BQWEsa0JBQW1CLFNBQVEsK0JBQWM7SUFDM0MsNkJBQTZCLENBQVU7SUFDdkMsT0FBTyxDQUFVO0lBRTFCLFlBQVksUUFBZ0IsRUFBRSxlQUFnQyxFQUFFLDRCQUFzQztRQUNwRyxLQUFLLENBQUMsUUFBUSxFQUFFLGVBQWUsQ0FBQyxDQUFDO1FBQ2pDLElBQUksQ0FBQyw2QkFBNkIsR0FBRy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MzQyxDQUFDO1FBQ0QsT0FBTyxJQUFJLENBQUM7SUFDZCxDQUFDO0NBQ0Y7QUEzR0QsZ0RBMkdDIn0=
|
|
@@ -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
|
+
import { MessageView } from '../message';
|
|
18
|
+
import { FifoConsumeService } from './FifoConsumeService';
|
|
19
|
+
import { MessageListener } from './MessageListener';
|
|
20
|
+
import type { ProcessQueue } from './ProcessQueue';
|
|
21
|
+
/**
|
|
22
|
+
* FIFO consume service for lite push consumer.
|
|
23
|
+
*
|
|
24
|
+
* <p>Similar to {@link FifoConsumeService}, but groups messages by lite topic
|
|
25
|
+
* instead of message group. This ensures messages with the same lite topic are
|
|
26
|
+
* consumed sequentially, while messages with different lite topics can be
|
|
27
|
+
* consumed in parallel when the accelerator is enabled.</p>
|
|
28
|
+
*
|
|
29
|
+
* <p>When the message listener returns {@link ConsumeResultSuspend}, all
|
|
30
|
+
* remaining messages with the same lite topic in the current batch are also
|
|
31
|
+
* suspended, while messages with different lite topics continue to be consumed.</p>
|
|
32
|
+
*/
|
|
33
|
+
export declare class LiteFifoConsumeService extends FifoConsumeService {
|
|
34
|
+
#private;
|
|
35
|
+
constructor(clientId: string, messageListener: MessageListener, enableFifoConsumeAccelerator?: boolean);
|
|
36
|
+
/**
|
|
37
|
+
* Use lite topic as the group key for FIFO consumption.
|
|
38
|
+
*
|
|
39
|
+
* @param messageView - The message view
|
|
40
|
+
* @return {string} The lite topic, empty string if not present
|
|
41
|
+
*/
|
|
42
|
+
protected getMessageGroupKey(messageView: MessageView): string;
|
|
43
|
+
protected consumeIteratively(pq: ProcessQueue, messageViews: MessageView[], startIndex: number): Promise<void>;
|
|
44
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
4
|
+
* contributor license agreements. See the NOTICE file distributed with
|
|
5
|
+
* this work for additional information regarding copyright ownership.
|
|
6
|
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
7
|
+
* (the "License"); you may not use this file except in compliance with
|
|
8
|
+
* the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.LiteFifoConsumeService = void 0;
|
|
20
|
+
const ConsumeResult_1 = require("./ConsumeResult");
|
|
21
|
+
const FifoConsumeService_1 = require("./FifoConsumeService");
|
|
22
|
+
const Logger_1 = require("../client/Logger");
|
|
23
|
+
/**
|
|
24
|
+
* FIFO consume service for lite push consumer.
|
|
25
|
+
*
|
|
26
|
+
* <p>Similar to {@link FifoConsumeService}, but groups messages by lite topic
|
|
27
|
+
* instead of message group. This ensures messages with the same lite topic are
|
|
28
|
+
* consumed sequentially, while messages with different lite topics can be
|
|
29
|
+
* consumed in parallel when the accelerator is enabled.</p>
|
|
30
|
+
*
|
|
31
|
+
* <p>When the message listener returns {@link ConsumeResultSuspend}, all
|
|
32
|
+
* remaining messages with the same lite topic in the current batch are also
|
|
33
|
+
* suspended, while messages with different lite topics continue to be consumed.</p>
|
|
34
|
+
*/
|
|
35
|
+
class LiteFifoConsumeService extends FifoConsumeService_1.FifoConsumeService {
|
|
36
|
+
#logger;
|
|
37
|
+
constructor(clientId, messageListener, enableFifoConsumeAccelerator) {
|
|
38
|
+
super(clientId, messageListener, enableFifoConsumeAccelerator);
|
|
39
|
+
this.#logger = (0, Logger_1.getDefaultLogger)();
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Use lite topic as the group key for FIFO consumption.
|
|
43
|
+
*
|
|
44
|
+
* @param messageView - The message view
|
|
45
|
+
* @return {string} The lite topic, empty string if not present
|
|
46
|
+
*/
|
|
47
|
+
getMessageGroupKey(messageView) {
|
|
48
|
+
return messageView.liteTopic || '';
|
|
49
|
+
}
|
|
50
|
+
consumeIteratively(pq, messageViews, startIndex) {
|
|
51
|
+
if (!pq || !messageViews) {
|
|
52
|
+
this.#logger.error('[Bug] Invalid arguments for consumeIteratively, pq=%s, messageViews=%s, clientId=%s', pq, messageViews, this.clientId);
|
|
53
|
+
return Promise.resolve();
|
|
54
|
+
}
|
|
55
|
+
const next = this.getNextValidMessage(pq, messageViews, startIndex);
|
|
56
|
+
if (!next) {
|
|
57
|
+
return Promise.resolve();
|
|
58
|
+
}
|
|
59
|
+
const { messageView, nextIndex } = next;
|
|
60
|
+
return this.consumeMessage(messageView)
|
|
61
|
+
.then(async (result) => {
|
|
62
|
+
await pq.eraseFifoMessage(messageView, result);
|
|
63
|
+
return result;
|
|
64
|
+
})
|
|
65
|
+
.then(async (result) => {
|
|
66
|
+
if (result instanceof ConsumeResult_1.ConsumeResultSuspend) {
|
|
67
|
+
const currentLiteTopic = messageView.liteTopic ?? '';
|
|
68
|
+
const continuation = [];
|
|
69
|
+
const suspendTasks = [];
|
|
70
|
+
// Suspend all messages with the same liteTopic in this batch.
|
|
71
|
+
for (let i = nextIndex; i < messageViews.length; i++) {
|
|
72
|
+
const msg = messageViews[i];
|
|
73
|
+
if ((msg.liteTopic ?? '') === currentLiteTopic) {
|
|
74
|
+
suspendTasks.push(pq.eraseFifoMessage(msg, result));
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
continuation.push(msg);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
this.#logger.debug?.('LiteFifoConsumeService suspend, liteTopic=%s, suspendCount=%d, continuationCount=%d, '
|
|
81
|
+
+ 'clientId=%s', currentLiteTopic, suspendTasks.length, continuation.length, this.clientId);
|
|
82
|
+
await Promise.all(suspendTasks);
|
|
83
|
+
return this.consumeIteratively(pq, continuation, 0);
|
|
84
|
+
}
|
|
85
|
+
return this.consumeIteratively(pq, messageViews, nextIndex);
|
|
86
|
+
})
|
|
87
|
+
.catch(err => {
|
|
88
|
+
this.#logger.error('[Bug] Exception raised in lite FIFO consumption callback, clientId=%s, error=%s', this.clientId, err);
|
|
89
|
+
return this.consumeIteratively(pq, messageViews, nextIndex);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.LiteFifoConsumeService = LiteFifoConsumeService;
|
|
94
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTGl0ZUZpZm9Db25zdW1lU2VydmljZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jb25zdW1lci9MaXRlRmlmb0NvbnN1bWVTZXJ2aWNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQTs7Ozs7Ozs7Ozs7Ozs7O0dBZUc7OztBQUdILG1EQUF1RDtBQUN2RCw2REFBMEQ7QUFHMUQsNkNBQT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csYUFBYSxFQUFFLGdCQUFnQixFQUFFLFlBQVksQ0FBQyxNQUFNLEVBQUUsWUFBWSxDQUFDLE1BQU0sRUFBRSxJQUFJLENBQUMsUUFBUSxDQUFDLENBQUM7Z0JBRTlGLE1BQU0sT0FBTyxDQUFDLEdBQUcsQ0FBQyxZQUFZLENBQUMsQ0FBQztnQkFDaEMsT0FBTyxJQUFJLENBQUMsa0JBQWtCLENBQUMsRUFBRSxFQUFFLFlBQVksRUFBRSxDQUFDLENBQUMsQ0FBQztZQUN0RCxDQUFDO1lBQ0QsT0FBTyxJQUFJLENBQUMsa0JBQWtCLENBQUMsRUFBRSxFQUFFLFlBQVksRUFBRSxTQUFTLENBQUMsQ0FBQztRQUM5RCxDQUFDLENBQUM7YUFDRCxLQUFLLENBQUMsR0FBRyxDQUFDLEVBQUU7WUFDWCxJQUFJLENBQUMsT0FBTyxDQUFDLEtBQUssQ0FBQyxpRkFBaUYsRUFDbEcsSUFBSSxDQUFDLFFBQVEsRUFBRSxHQUFHLENBQUMsQ0FBQztZQUN0QixPQUFPLElBQUksQ0FBQyxrQkFBa0IsQ0FBQyxFQUFFLEVBQUUsWUFBWSxFQUFFLFNBQVMsQ0FBQyxDQUFDO1FBQzlELENBQUMsQ0FBQyxDQUFDO0lBQ1AsQ0FBQztDQUNGO0FBbEVELHdEQWtFQyJ9
|
|
@@ -82,6 +82,10 @@ export interface LitePushConsumerOptions extends BaseClientOptions {
|
|
|
82
82
|
consumerGroup: string;
|
|
83
83
|
bindTopic: string;
|
|
84
84
|
messageListener: MessageListener;
|
|
85
|
+
maxCacheMessageCount?: number;
|
|
86
|
+
maxCacheMessageSizeInBytes?: number;
|
|
87
|
+
consumptionThreadCount?: number;
|
|
88
|
+
enableFifoConsumeAccelerator?: boolean;
|
|
85
89
|
}
|
|
86
90
|
/**
|
|
87
91
|
* LitePushConsumer builder class.
|
|
@@ -147,6 +151,16 @@ export declare class LitePushConsumerBuilder {
|
|
|
147
151
|
* @throws Error if consumptionThreadCount is not positive
|
|
148
152
|
*/
|
|
149
153
|
setConsumptionThreadCount(consumptionThreadCount: number): LitePushConsumerBuilder;
|
|
154
|
+
/**
|
|
155
|
+
* Set enable fifo consume accelerator.
|
|
156
|
+
*
|
|
157
|
+
* <p>If enabled, messages with different messageGroups are consumed in parallel
|
|
158
|
+
* while messages within the same messageGroup are consumed sequentially.</p>
|
|
159
|
+
*
|
|
160
|
+
* @param enableFifoConsumeAccelerator - Whether to enable FIFO consume accelerator
|
|
161
|
+
* @return This builder instance
|
|
162
|
+
*/
|
|
163
|
+
setEnableFifoConsumeAccelerator(enableFifoConsumeAccelerator: boolean): LitePushConsumerBuilder;
|
|
150
164
|
/**
|
|
151
165
|
* Finalize the build of LitePushConsumer and start.
|
|
152
166
|
*
|
|
@@ -97,7 +97,7 @@ class LitePushConsumerBuilder {
|
|
|
97
97
|
if (maxCacheMessageCount <= 0) {
|
|
98
98
|
throw new Error('maxCacheMessageCount should be positive');
|
|
99
99
|
}
|
|
100
|
-
|
|
100
|
+
this.options.maxCacheMessageCount = maxCacheMessageCount;
|
|
101
101
|
return this;
|
|
102
102
|
}
|
|
103
103
|
/**
|
|
@@ -111,7 +111,7 @@ class LitePushConsumerBuilder {
|
|
|
111
111
|
if (maxCacheMessageSizeInBytes <= 0) {
|
|
112
112
|
throw new Error('maxCacheMessageSizeInBytes should be positive');
|
|
113
113
|
}
|
|
114
|
-
|
|
114
|
+
this.options.maxCacheMessageSizeInBytes = maxCacheMessageSizeInBytes;
|
|
115
115
|
return this;
|
|
116
116
|
}
|
|
117
117
|
/**
|
|
@@ -125,7 +125,24 @@ class LitePushConsumerBuilder {
|
|
|
125
125
|
if (consumptionThreadCount <= 0) {
|
|
126
126
|
throw new Error('consumptionThreadCount should be positive');
|
|
127
127
|
}
|
|
128
|
-
//
|
|
128
|
+
// Note: Node.js uses a single-threaded event loop model, so this configuration
|
|
129
|
+
// has no effect on actual consumption concurrency. It is retained solely for
|
|
130
|
+
// API compatibility with the other clients. Consumption concurrency in Node.js
|
|
131
|
+
// is naturally managed by the event loop and Promise-based async scheduling.
|
|
132
|
+
this.options.consumptionThreadCount = consumptionThreadCount;
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Set enable fifo consume accelerator.
|
|
137
|
+
*
|
|
138
|
+
* <p>If enabled, messages with different messageGroups are consumed in parallel
|
|
139
|
+
* while messages within the same messageGroup are consumed sequentially.</p>
|
|
140
|
+
*
|
|
141
|
+
* @param enableFifoConsumeAccelerator - Whether to enable FIFO consume accelerator
|
|
142
|
+
* @return This builder instance
|
|
143
|
+
*/
|
|
144
|
+
setEnableFifoConsumeAccelerator(enableFifoConsumeAccelerator) {
|
|
145
|
+
this.options.enableFifoConsumeAccelerator = enableFifoConsumeAccelerator;
|
|
129
146
|
return this;
|
|
130
147
|
}
|
|
131
148
|
/**
|
|
@@ -162,6 +179,10 @@ class LitePushConsumerBuilder {
|
|
|
162
179
|
sessionCredentials: this.options.sessionCredentials,
|
|
163
180
|
requestTimeout: this.options.requestTimeout,
|
|
164
181
|
logger: this.options.logger,
|
|
182
|
+
maxCacheMessageCount: this.options.maxCacheMessageCount,
|
|
183
|
+
maxCacheMessageSizeInBytes: this.options.maxCacheMessageSizeInBytes,
|
|
184
|
+
consumptionThreadCount: this.options.consumptionThreadCount,
|
|
185
|
+
enableFifoConsumeAccelerator: this.options.enableFifoConsumeAccelerator,
|
|
165
186
|
};
|
|
166
187
|
const litePushConsumer = new LitePushConsumerImpl_1.LitePushConsumerImpl(options);
|
|
167
188
|
await litePushConsumer.startup();
|
|
@@ -169,4 +190,4 @@ class LitePushConsumerBuilder {
|
|
|
169
190
|
}
|
|
170
191
|
}
|
|
171
192
|
exports.LitePushConsumerBuilder = LitePushConsumerBuilder;
|
|
172
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
193
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTGl0ZVB1c2hDb25zdW1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FDM0QsTUFBTSxnQkFBZ0IsQ0FBQyxPQUFPLEVBQUUsQ0FBQztRQUNqQyxPQUFPLGdCQUFnQixDQUFDO0lBQzFCLENBQUM7Q0FDRjtBQTlLRCwwREE4S0MifQ==
|
|
@@ -20,6 +20,7 @@ import { Endpoints, TopicRouteData } from '../route';
|
|
|
20
20
|
import { PushConsumer, PushConsumerOptions } from './PushConsumer';
|
|
21
21
|
import { LitePushConsumer } from './LitePushConsumer';
|
|
22
22
|
import { OffsetOption } from './OffsetOption';
|
|
23
|
+
import { ConsumeService } from './ConsumeService';
|
|
23
24
|
export interface LitePushConsumerOptions extends PushConsumerOptions {
|
|
24
25
|
bindTopic: string;
|
|
25
26
|
}
|
|
@@ -42,9 +43,17 @@ export interface LitePushConsumerOptions extends PushConsumerOptions {
|
|
|
42
43
|
* because it uses the assignment-based message delivery mechanism managed by the server.</p>
|
|
43
44
|
*/
|
|
44
45
|
export declare class LitePushConsumerImpl extends PushConsumer implements LitePushConsumer {
|
|
46
|
+
#private;
|
|
45
47
|
private readonly liteSubscriptionManager;
|
|
46
48
|
private readonly bindTopic;
|
|
47
49
|
constructor(options: LitePushConsumerOptions);
|
|
50
|
+
/**
|
|
51
|
+
* Create the consume service for lite push consumer.
|
|
52
|
+
*
|
|
53
|
+
* <p>Lite push consumer uses lite-topic-specific consume services to ensure
|
|
54
|
+
* correct grouping and retry behavior.</p>
|
|
55
|
+
*/
|
|
56
|
+
protected createConsumeService(): ConsumeService;
|
|
48
57
|
/**
|
|
49
58
|
* Get the client type.
|
|
50
59
|
*
|