@aitickets123654/common-kafka 1.0.17 → 1.0.18

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,4 +1,4 @@
1
- import { Producer, Admin } from 'kafkajs';
1
+ import { Producer } from 'kafkajs';
2
2
  import { Topics } from './topics';
3
3
  interface Event {
4
4
  topic: Topics;
@@ -7,9 +7,7 @@ interface Event {
7
7
  export declare abstract class Publisher<T extends Event> {
8
8
  abstract topic: T['topic'];
9
9
  protected producer: Producer;
10
- protected admin: Admin;
11
- protected constructor(producer: Producer, admin: Admin);
12
- private ensureTopicExists;
10
+ protected constructor(producer: Producer);
13
11
  publish(data: T['data']): Promise<void>;
14
12
  }
15
13
  export {};
@@ -2,45 +2,44 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Publisher = void 0;
4
4
  class Publisher {
5
- constructor(producer, admin) {
5
+ // protected admin: Admin;
6
+ constructor(producer /*, admin: Admin*/) {
6
7
  this.producer = producer;
7
- this.admin = admin;
8
- }
9
- async ensureTopicExists() {
10
- try {
11
- const topics = await this.admin.listTopics();
12
- if (!topics.includes(this.topic)) {
13
- await this.admin.createTopics({
14
- topics: [
15
- {
16
- topic: this.topic,
17
- numPartitions: 2,
18
- replicationFactor: 1,
19
- },
20
- ],
21
- waitForLeaders: true,
22
- validateOnly: false,
23
- timeout: 5000,
24
- });
25
- console.log(`Topic '${this.topic}' created`);
26
- }
27
- else {
28
- console.log(`Topic '${this.topic}' already exists`);
29
- }
30
- }
31
- catch (err) {
32
- console.error(`Failed to ensure topic '${this.topic}':`, err);
33
- throw err;
34
- }
8
+ // this.admin = admin;
35
9
  }
10
+ // private async ensureTopicExists(): Promise<void> {
11
+ // try {
12
+ // const topics = await this.admin.listTopics();
13
+ // if (!topics.includes(this.topic)) {
14
+ // await this.admin.createTopics({
15
+ // topics: [
16
+ // {
17
+ // topic: this.topic,
18
+ // numPartitions: 2,
19
+ // replicationFactor: 1,
20
+ // },
21
+ // ],
22
+ // waitForLeaders: true,
23
+ // validateOnly: false,
24
+ // timeout: 5000,
25
+ // });
26
+ // // console.log(`Topic '${this.topic}' created`);
27
+ // } else {
28
+ // // console.log(`Topic '${this.topic}' already exists`);
29
+ // }
30
+ // } catch (err) {
31
+ // console.error(`Failed to ensure topic '${this.topic}':`, err);
32
+ // throw err;
33
+ // }
34
+ // }
36
35
  async publish(data) {
37
- await this.ensureTopicExists();
36
+ // await this.ensureTopicExists();
38
37
  try {
39
38
  await this.producer.send({
40
39
  topic: this.topic,
41
40
  messages: [{ value: JSON.stringify(data) }],
42
41
  });
43
- console.log(`Event published to topic '${this.topic}'`, `\ndata: ${JSON.stringify(data, null, 2)}`);
42
+ // console.log(`Event published to topic '${this.topic}'`, `\ndata: ${JSON.stringify(data, null, 2)}`);
44
43
  }
45
44
  catch (err) {
46
45
  console.error('Failed to publish event:', err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aitickets123654/common-kafka",
3
- "version": "1.0.17",
3
+ "version": "1.0.18",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",