@aichatwar/shared 1.0.125 → 1.0.127

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.
@@ -6,6 +6,7 @@ export declare abstract class Listener<T extends BaseEvent> {
6
6
  abstract onMessage(data: T['data'], payload: EachMessagePayload): Promise<void>;
7
7
  protected consumer: Consumer;
8
8
  protected ackDeadline: number;
9
+ protected fromBeginning: boolean;
9
10
  private currentPayload?;
10
11
  private retryCount;
11
12
  private readonly maxInitialRetries;
@@ -13,6 +13,7 @@ exports.Listener = void 0;
13
13
  class Listener {
14
14
  constructor(consumer) {
15
15
  this.ackDeadline = 5 * 1000; // 5 seconds
16
+ this.fromBeginning = false; // Override in subclasses to read from beginning
16
17
  this.retryCount = 0;
17
18
  this.maxInitialRetries = 3; // Show detailed retry logs for first 3 attempts
18
19
  this.maxRetryDelay = 60000; // Cap delay at 60 seconds
@@ -67,10 +68,10 @@ class Listener {
67
68
  yield this.consumer.connect();
68
69
  console.log(`✅ [${this.topic}] Consumer connected`);
69
70
  // Crash handler is set up in constructor, no need to add it again
70
- console.log(`📋 [${this.topic}] Subscribing to topic...`);
71
+ console.log(`📋 [${this.topic}] Subscribing to topic... (fromBeginning: ${this.fromBeginning})`);
71
72
  yield this.consumer.subscribe({
72
73
  topic: this.topic,
73
- fromBeginning: false,
74
+ fromBeginning: this.fromBeginning,
74
75
  });
75
76
  console.log(`✅ [${this.topic}] Successfully subscribed to topic with groupId: ${this.groupId}`);
76
77
  // Log success message, especially if there were previous retries
@@ -24,11 +24,12 @@ class Publisher {
24
24
  let lastError = null;
25
25
  for (let attempt = 1; attempt <= this.maxRetries; attempt++) {
26
26
  try {
27
+ const messageKey = data.id || undefined; // Use id as key for partitioning if available
27
28
  const result = yield this.producer.send({
28
29
  topic: this.topic,
29
30
  messages: [{
30
31
  value: JSON.stringify(data),
31
- key: data.id || undefined, // Use id as key for partitioning if available
32
+ key: messageKey,
32
33
  timestamp: Date.now().toString()
33
34
  }],
34
35
  });
@@ -36,6 +37,7 @@ class Publisher {
36
37
  topic: this.topic,
37
38
  partition: (_a = result[0]) === null || _a === void 0 ? void 0 : _a.partition,
38
39
  offset: (_b = result[0]) === null || _b === void 0 ? void 0 : _b.offset,
40
+ key: (messageKey === null || messageKey === void 0 ? void 0 : messageKey.toString()) || 'none',
39
41
  data: JSON.stringify(data).substring(0, 200) // First 200 chars for brevity
40
42
  });
41
43
  return; // Success, exit retry loop
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aichatwar/shared",
3
- "version": "1.0.125",
3
+ "version": "1.0.127",
4
4
  "main": "./build/index.js",
5
5
  "typs": "./build/index.d.ts",
6
6
  "files": [