@aichatwar/shared 1.0.85 → 1.0.87
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.
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Producer } from "kafkajs";
|
|
2
2
|
import { BaseEvent } from '../baseEvent';
|
|
3
3
|
export declare abstract class Publisher<T extends BaseEvent> {
|
|
4
|
-
abstract topic: T[
|
|
5
|
-
|
|
6
|
-
constructor(
|
|
7
|
-
|
|
8
|
-
publish(data: T["data"]): Promise<void>;
|
|
4
|
+
abstract topic: T['subject'];
|
|
5
|
+
protected producer: Producer;
|
|
6
|
+
constructor(producer: Producer);
|
|
7
|
+
publish(data: T['data']): Promise<void>;
|
|
9
8
|
}
|
|
@@ -10,23 +10,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.Publisher = void 0;
|
|
13
|
-
// Updated event to base event
|
|
14
13
|
class Publisher {
|
|
15
|
-
constructor(
|
|
16
|
-
this.producer =
|
|
17
|
-
}
|
|
18
|
-
connect() {
|
|
19
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
yield this.producer.connect();
|
|
21
|
-
});
|
|
14
|
+
constructor(producer) {
|
|
15
|
+
this.producer = producer;
|
|
22
16
|
}
|
|
23
17
|
publish(data) {
|
|
24
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
19
|
+
if (!this.producer)
|
|
20
|
+
throw new Error('Producer not defined');
|
|
21
|
+
try {
|
|
22
|
+
yield this.producer.send({
|
|
23
|
+
topic: this.topic,
|
|
24
|
+
messages: [{ value: JSON.stringify(data) }],
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
console.error(`❌ Publish failed on first try for ${this.topic}`, err);
|
|
29
|
+
throw err;
|
|
30
|
+
}
|
|
30
31
|
});
|
|
31
32
|
}
|
|
32
33
|
}
|