@kaapi/kafka-messaging 0.0.16 → 0.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.
package/package.json CHANGED
@@ -1,9 +1,15 @@
1
1
  {
2
2
  "name": "@kaapi/kafka-messaging",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "private": false,
5
5
  "description": "Kafka-based messaging for kaapi",
6
6
  "main": "lib/index.js",
7
+ "keywords": [
8
+ "kaapi",
9
+ "messaging",
10
+ "kafka",
11
+ "typescript"
12
+ ],
7
13
  "author": "demingongo",
8
14
  "repository": {
9
15
  "type": "git",
@@ -14,14 +20,13 @@
14
20
  "dependencies": {
15
21
  "kafkajs": "^2.2.4",
16
22
  "tslib": "^2.8.1",
17
- "@kaapi/kaapi": "^0.0.16"
23
+ "@kaapi/kaapi": "^0.0.18"
18
24
  },
19
25
  "devDependencies": {
20
26
  "@types/mocha": "^10.0.10"
21
27
  },
22
28
  "scripts": {
23
29
  "lint": "eslint .",
24
- "build": "tsc",
25
- "test": "echo \"Error: no test specified\" && exit 1"
30
+ "build": "tsc"
26
31
  }
27
32
  }
@@ -1,129 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-unused-expressions */
2
-
3
- // test/kafka-messaging.spec.ts
4
-
5
- import { expect } from 'chai';
6
- import { KafkaMessaging } from '../src/index';
7
-
8
- describe('KafkaMessaging', () => {
9
- const kafkaConfig = {
10
- clientId: 'test-client',
11
- brokers: process.env.KAFKA_BROKERS ? process.env.KAFKA_BROKERS.split(',') : ['localhost:9092'],
12
- };
13
-
14
- let messaging: KafkaMessaging;
15
-
16
- beforeEach(() => {
17
- messaging = new KafkaMessaging(kafkaConfig);
18
- });
19
-
20
- it('should create and track a producer', async () => {
21
- const producer = await messaging.createProducer();
22
- expect(producer).to.exist;
23
- if (producer)
24
- expect(messaging.activeProducers.has(producer)).to.be.true;
25
- });
26
-
27
- it('should create and track a consumer', async () => {
28
- const consumer = await messaging.createConsumer('test-group');
29
- expect(consumer).to.exist;
30
- if (consumer)
31
- expect(messaging.activeConsumers.has(consumer)).to.be.true;
32
- });
33
-
34
- it('should disconnect producer safely', async () => {
35
- const producer = await messaging.createProducer();
36
- expect(producer).to.exist;
37
-
38
- if (producer) {
39
- await messaging.safeDisconnect(producer);
40
- expect(messaging.activeProducers.has(producer)).to.be.false;
41
- }
42
- });
43
-
44
- it('should disconnect consumer safely', async () => {
45
- const consumer = await messaging.createConsumer('test-group');
46
- expect(consumer).to.exist;
47
- if (consumer) {
48
- await consumer.stop();
49
- await messaging.safeDisconnect(consumer);
50
- expect(messaging.activeConsumers.has(consumer)).to.be.false;
51
- }
52
- });
53
-
54
- it('should shutdown all tracked clients', async () => {
55
- await messaging.createProducer();
56
- await messaging.createConsumer('test-group');
57
- const result = await messaging.shutdown();
58
- expect(result.successProducers).to.be.greaterThan(0);
59
- expect(result.successConsumers).to.be.greaterThan(0);
60
- expect(result.errorCount).to.equal(0);
61
- });
62
- });
63
-
64
- describe('KafkaMessaging Integration', function () {
65
- this.timeout(20000); // Increase timeout for Kafka operations
66
-
67
- const kafkaConfig = {
68
- clientId: 'integration-client',
69
- brokers: process.env.KAFKA_BROKERS ? process.env.KAFKA_BROKERS.split(',') : ['localhost:9092'],
70
- };
71
-
72
- let messaging: KafkaMessaging;
73
-
74
- beforeEach(() => {
75
- messaging = new KafkaMessaging(kafkaConfig);
76
- });
77
-
78
- afterEach(async () => {
79
- await messaging.shutdown();
80
- });
81
-
82
- it('should publish and consume a message', async () => {
83
- const topic = 'test-topic-c';
84
- await messaging.createTopic({
85
- topic,
86
- numPartitions: 1,
87
- replicationFactor: 1
88
- }, {
89
- waitForLeaders: true
90
- });
91
- await messaging.waitForTopicReady(topic); // 👈 wait for metadata to settle
92
-
93
- const message = { hello: 'world' };
94
-
95
- let received: unknown = null;
96
-
97
- await messaging.subscribe(topic, (msg) => {
98
- received = msg;
99
- }, { fromBeginning: true });
100
-
101
- await messaging.publish(topic, message);
102
-
103
- // Wait for message to be consumed
104
- await new Promise(resolve => setTimeout(resolve, 1000));
105
-
106
- expect(received).to.deep.equal(message);
107
- });
108
-
109
- it('should return correct shutdown summary', async () => {
110
- const topic = 'shutdown-topic-c';
111
- await messaging.createTopic({
112
- topic,
113
- numPartitions: 1,
114
- replicationFactor: 1
115
- }, {
116
- waitForLeaders: true
117
- });
118
- await messaging.waitForTopicReady(topic); // 👈 wait for metadata to settle
119
-
120
- await messaging.subscribe(topic, () => { }, { fromBeginning: true });
121
- await messaging.publish(topic, { test: true });
122
-
123
- const result = await messaging.shutdown();
124
-
125
- expect(result.successProducers).to.be.greaterThan(0);
126
- expect(result.successConsumers).to.be.greaterThan(0);
127
- expect(result.errorCount).to.equal(0);
128
- });
129
- });