Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

kafka-node

Package Overview
Dependencies
Maintainers
3
Versions
113
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kafka-node

Client for Apache Kafka v0.9.x, v0.10.x and v0.11.x

  • 4.0.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
168K
increased by2.27%
Maintainers
3
Weekly downloads
 
Created

What is kafka-node?

The kafka-node package is a client library for Apache Kafka, a distributed streaming platform. It allows you to produce and consume messages, manage Kafka topics, and handle Kafka streams in Node.js applications.

What are kafka-node's main functionalities?

Producer

This feature allows you to produce messages to a Kafka topic. The code sample demonstrates how to create a Kafka producer, connect to a Kafka broker, and send a message to a specified topic.

const kafka = require('kafka-node');
const client = new kafka.KafkaClient({kafkaHost: 'localhost:9092'});
const producer = new kafka.Producer(client);
const payloads = [
  { topic: 'topic1', messages: 'hello world', partition: 0 }
];
producer.on('ready', function () {
  producer.send(payloads, function (err, data) {
    console.log(data);
  });
});
producer.on('error', function (err) {
  console.error('Producer error:', err);
});

Consumer

This feature allows you to consume messages from a Kafka topic. The code sample demonstrates how to create a Kafka consumer, connect to a Kafka broker, and listen for messages on a specified topic.

const kafka = require('kafka-node');
const client = new kafka.KafkaClient({kafkaHost: 'localhost:9092'});
const consumer = new kafka.Consumer(
  client,
  [
    { topic: 'topic1', partition: 0 }
  ],
  {
    autoCommit: true
  }
);
consumer.on('message', function (message) {
  console.log(message);
});
consumer.on('error', function (err) {
  console.error('Consumer error:', err);
});

Admin

This feature allows you to perform administrative tasks such as listing topics. The code sample demonstrates how to create an admin client and list all topics in the Kafka cluster.

const kafka = require('kafka-node');
const client = new kafka.KafkaClient({kafkaHost: 'localhost:9092'});
const admin = new kafka.Admin(client);
admin.listTopics((err, res) => {
  console.log(res);
});

Other packages similar to kafka-node

Keywords

FAQs

Package last updated on 28 Mar 2019

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc