-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
52 lines (46 loc) · 1.17 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { Kafka } from 'kafkajs';
import consumerCheck from './consumerCheck';
import { FIRST_CONSUMER_GROUP_ID,
SECOND_CONSUMER_GROUP_ID,
FIRST_CONSUMER_GROUP_CONSUMER_COUNT,
SECOND_CONSUMER_GROUP_CONSUMER_COUNT,
FIRST_TOPIC,
SECOND_TOPIC} from './constants';
import { messageProcessor } from './messageProcessor';
import { spawnConsumer } from './spawnConsumer';
import { produceMessages } from './produceMessages';
const kafka = new Kafka({
clientId: 'my-app',
brokers: ['localhost:9092']
});
const consumerSpawners = {
[FIRST_CONSUMER_GROUP_ID]: () => spawnConsumer(
kafka,
messageProcessor,
FIRST_CONSUMER_GROUP_ID,
FIRST_TOPIC
),
[SECOND_CONSUMER_GROUP_ID]: () => spawnConsumer(
kafka,
messageProcessor,
SECOND_CONSUMER_GROUP_ID,
SECOND_TOPIC
),
};
void consumerCheck(kafka, consumerSpawners)
for (
let i = 0;
i < FIRST_CONSUMER_GROUP_CONSUMER_COUNT;
i++
) {
spawnConsumer(kafka, messageProcessor, FIRST_CONSUMER_GROUP_ID, FIRST_TOPIC)
}
for (
let i = 0;
i < SECOND_CONSUMER_GROUP_CONSUMER_COUNT;
i++
) {
spawnConsumer(kafka, messageProcessor, SECOND_CONSUMER_GROUP_ID, SECOND_TOPIC)
}
const producer = kafka.producer();
produceMessages(producer);