Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
kafkajs-stream
Advanced tools
tested in Node.js v12
import fs from "fs";
import http from "http";
import gracefulShutdown from "http-graceful-shutdown";
import { CompressionCodecs, CompressionTypes, Kafka } from "kafkajs";
import SnappyCodec from "kafkajs-snappy";
import { times } from "lodash";
import { from } from "rxjs";
import { rxToStream } from "rxjs-stream";
import app from "./app";
import { ConsumerStream, ProducerStream } from "kafkajs-stream";
const { PORT = 4000 } = process.env;
CompressionCodecs[CompressionTypes.Snappy] = SnappyCodec;
const kafka = new Kafka({
clientId: "my-app",
brokers: ["bitnami-kafka:9092"]
});
// Producing
const producerStream = new ProducerStream(kafka, { topic: "test-topic" });
const number$ = from(times(200000, i => `${i.toString()},`));
rxToStream(number$).pipe(producerStream);
// Consuming
const consumerStream = new ConsumerStream(kafka, {
config: { groupId: "test-group" },
topic: { topic: "test-topic", fromBeginning: true }
});
const producer2Stream = new ProducerStream(kafka, { topic: "test-topic-2" });
consumerStream.pipe(producer2Stream);
const consumerStream2 = new ConsumerStream(kafka, {
config: { groupId: "test-group-2" },
topic: { topic: "test-topic-2", fromBeginning: true }
});
const writeStream = fs.createWriteStream("./testWrite.txt");
consumerStream2.pipe(writeStream);
(async () => {
const server = http.createServer(app);
server.listen(PORT);
// register graceful shutdown
gracefulShutdown(server, {
onShutdown: async () => {
await new Promise(resolve => producerStream.end(resolve));
consumerStream.destroy();
await new Promise(resolve => producer2Stream.end(resolve));
consumerStream2.destroy();
await new Promise(resolve => writeStream.end(resolve));
}
});
server.on("listening", () => {
console.log(`application is listening on port ${PORT}`);
});
})();
FAQs
Stream for kafkajs
The npm package kafkajs-stream receives a total of 37 weekly downloads. As such, kafkajs-stream popularity was classified as not popular.
We found that kafkajs-stream demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.