@aichatwar/shared 1.0.124 → 1.0.126

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.
@@ -59,29 +59,33 @@ class Listener {
59
59
  var _a;
60
60
  // Prevent multiple simultaneous listen attempts
61
61
  if (this.isListening) {
62
+ console.log(`⚠️ [${this.topic}] Listener already listening, skipping...`);
62
63
  return;
63
64
  }
64
65
  try {
66
+ console.log(`🔌 [${this.topic}] Connecting consumer with groupId: ${this.groupId}`);
65
67
  yield this.consumer.connect();
68
+ console.log(`✅ [${this.topic}] Consumer connected`);
66
69
  // Crash handler is set up in constructor, no need to add it again
70
+ console.log(`📋 [${this.topic}] Subscribing to topic...`);
67
71
  yield this.consumer.subscribe({
68
72
  topic: this.topic,
69
73
  fromBeginning: false,
70
74
  });
75
+ console.log(`✅ [${this.topic}] Successfully subscribed to topic with groupId: ${this.groupId}`);
71
76
  // Log success message, especially if there were previous retries
72
77
  if (this.retryCount > 0) {
73
78
  console.log(`✅ [${this.topic}] Successfully connected after ${this.retryCount} retry attempts. Listening with groupId: ${this.groupId}`);
74
79
  }
75
- else {
76
- console.log(`✅ [${this.topic}] Successfully connected. Listening to topic with groupId: ${this.groupId}`);
77
- }
78
80
  // Reset retry count on successful connection
79
81
  this.retryCount = 0;
82
+ console.log(`🚀 [${this.topic}] Starting consumer.run() with groupId: ${this.groupId}`);
80
83
  yield this.consumer.run({
81
84
  // CRITICAL: Disable auto-commit to prevent message loss during rebalancing
82
85
  // Offsets are only committed when we explicitly call ack()
83
86
  autoCommit: false,
84
87
  eachMessage: (payload) => __awaiter(this, void 0, void 0, function* () {
88
+ var _a;
85
89
  if (!payload.message.value) {
86
90
  // Acknowledge empty messages to avoid blocking
87
91
  yield this.consumer.commitOffsets([{
@@ -91,7 +95,7 @@ class Listener {
91
95
  }]);
92
96
  return;
93
97
  }
94
- console.log(`Message received -> topic: ${this.topic}, groupId: ${this.groupId}, offset: ${payload.message.offset}`);
98
+ console.log(`📨 [${this.topic}] Message received -> groupId: ${this.groupId}, partition: ${payload.partition}, offset: ${payload.message.offset}, key: ${((_a = payload.message.key) === null || _a === void 0 ? void 0 : _a.toString()) || 'none'}`);
95
99
  // Store current payload for manual ack
96
100
  this.currentPayload = payload;
97
101
  try {
@@ -18,20 +18,28 @@ class Publisher {
18
18
  }
19
19
  publish(data) {
20
20
  return __awaiter(this, void 0, void 0, function* () {
21
+ var _a, _b;
21
22
  if (!this.producer)
22
23
  throw new Error('Producer not defined');
23
24
  let lastError = null;
24
25
  for (let attempt = 1; attempt <= this.maxRetries; attempt++) {
25
26
  try {
26
- yield this.producer.send({
27
+ const messageKey = data.id || undefined; // Use id as key for partitioning if available
28
+ const result = yield this.producer.send({
27
29
  topic: this.topic,
28
30
  messages: [{
29
31
  value: JSON.stringify(data),
30
- key: data.id || undefined, // Use id as key for partitioning if available
32
+ key: messageKey,
31
33
  timestamp: Date.now().toString()
32
34
  }],
33
35
  });
34
- console.log(`Event published successfully: ${this.topic}`, data);
36
+ console.log(`✅ Event published successfully: ${this.topic}`, {
37
+ topic: this.topic,
38
+ partition: (_a = result[0]) === null || _a === void 0 ? void 0 : _a.partition,
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',
41
+ data: JSON.stringify(data).substring(0, 200) // First 200 chars for brevity
42
+ });
35
43
  return; // Success, exit retry loop
36
44
  }
37
45
  catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aichatwar/shared",
3
- "version": "1.0.124",
3
+ "version": "1.0.126",
4
4
  "main": "./build/index.js",
5
5
  "typs": "./build/index.d.ts",
6
6
  "files": [