@aichatwar/shared 1.0.167 → 1.0.168
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.
|
@@ -8,6 +8,7 @@ export declare abstract class Listener<T extends BaseEvent> {
|
|
|
8
8
|
protected consumer: Consumer;
|
|
9
9
|
protected ackDeadline: number;
|
|
10
10
|
protected fromBeginning: boolean;
|
|
11
|
+
protected maxEventAgeMs: number;
|
|
11
12
|
private currentPayload?;
|
|
12
13
|
private retryCount;
|
|
13
14
|
private readonly maxInitialRetries;
|
|
@@ -14,6 +14,7 @@ class Listener {
|
|
|
14
14
|
constructor(consumer) {
|
|
15
15
|
this.ackDeadline = 5 * 1000; // 5 seconds
|
|
16
16
|
this.fromBeginning = false; // Override in subclasses to read from beginning
|
|
17
|
+
this.maxEventAgeMs = 0; // 0 = disabled. When set, messages older than this are auto-acked and skipped.
|
|
17
18
|
this.retryCount = 0;
|
|
18
19
|
this.maxInitialRetries = 3; // Show detailed retry logs for first 3 attempts
|
|
19
20
|
this.maxRetryDelay = 60000; // Cap delay at 60 seconds
|
|
@@ -121,6 +122,18 @@ class Listener {
|
|
|
121
122
|
// Commented out key logging as requested
|
|
122
123
|
// console.log(`📨 [${this.topic}] Message received -> groupId: ${this.groupId}, partition: ${payload.partition}, offset: ${payload.message.offset}, key: ${payload.message.key?.toString() || 'none'}`);
|
|
123
124
|
console.log(`📨 [${this.topic}] Message received -> groupId: ${this.groupId}, partition: ${payload.partition}, offset: ${payload.message.offset}, value length: ${payload.message.value.toString().length}`);
|
|
125
|
+
// Skip stale messages when maxEventAgeMs is configured
|
|
126
|
+
if (this.maxEventAgeMs > 0 && payload.message.timestamp) {
|
|
127
|
+
const messageAge = Date.now() - Number(payload.message.timestamp);
|
|
128
|
+
if (messageAge > this.maxEventAgeMs) {
|
|
129
|
+
yield this.consumer.commitOffsets([{
|
|
130
|
+
topic: payload.topic,
|
|
131
|
+
partition: payload.partition,
|
|
132
|
+
offset: (BigInt(payload.message.offset) + BigInt(1)).toString()
|
|
133
|
+
}]);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
124
137
|
// Store current payload for manual ack
|
|
125
138
|
this.currentPayload = payload;
|
|
126
139
|
try {
|