-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moving kafka to worker threads (#1963)
- Loading branch information
Showing
4 changed files
with
36 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Worker } from "worker_threads"; | ||
|
||
export function startConsumers({ | ||
normalCount, | ||
dlqCount, | ||
}: { | ||
normalCount: number; | ||
dlqCount: number; | ||
}) { | ||
for (let i = 0; i < normalCount; i++) { | ||
const worker = new Worker(`${__dirname}/kafkaConsumer.js`); | ||
worker.postMessage("start"); | ||
} | ||
|
||
for (let i = 0; i < dlqCount; i++) { | ||
const workerDlq = new Worker(`${__dirname}/kafkaConsumer.js`); | ||
workerDlq.postMessage("start-dlq"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
import { parentPort } from "worker_threads"; | ||
import { consume } from "./../lib/clients/KafkaConsumer"; | ||
import { consume, consumeDlq } from "./../lib/clients/KafkaConsumer"; | ||
|
||
parentPort?.once("message", (message) => { | ||
if (message === "start") { | ||
console.log("Kafka consumer thread started!"); | ||
consume(); | ||
} else if (message === "start-dlq") { | ||
console.log("Kafka DLQ consumer thread started!"); | ||
consumeDlq(); | ||
} | ||
}); |