npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@confluentinc/kafka-javascript

v1.0.0

Published

Node.js bindings for librdkafka

Downloads

52,415

Readme

Confluent's JavaScript Client for Apache KafkaTM

confluent-kafka-javascript is Confluent's JavaScript client for Apache Kafka and the Confluent Platform. The goal is to provide an highly performant, reliable and easy to use JavaScript client that is based on node-rdkafka yet also API compatible with KafkaJS to provide flexibility to users and streamline migrations from other clients.

Features:

  • High performance - confluent-kafka-javascript is a lightweight wrapper around librdkafka, a finely tuned C client.

  • Reliability - There are a lot of details to get right when writing an Apache Kafka client. We get them right in one place (librdkafka) and leverage this work across all of our clients.

  • Supported - Commercial support is offered by Confluent.

  • Future proof - Confluent, founded by the creators of Kafka, is building a streaming platform with Apache Kafka at its core. It's high priority for us that client features keep pace with core Apache Kafka and components of the Confluent Platform.

This library leverages the work and concepts from two popular Apache Kafka JavaScript clients: node-rdkafka and KafkaJS. The core is heavily based on the node-rdkafka library, which uses our own librdkafka library for core client functionality. However, we leverage a promisified API and a more idiomatic interface, similar to the one in KafkaJS, making it easy for developers to migrate and adopt this client depending on the patterns and interface they prefer. We're very happy to have been able to leverage the excellent work of the many authors of these libraries!

To use Schema Registry, use the @confluentinc/schemaregistry library that is compatible with this library. For a simple schema registry example, see sr.js.

Requirements

The following configurations are supported:

  • Any supported version of Node.js (The two LTS versions, 18 and 20, and the latest versions, 21, 22 and 23).
  • Linux (x64 and arm64) - both glibc and musl/alpine.
  • macOS - arm64/m1. macOS (Intel) is supported on a best-effort basis.
  • Windows - x64.

Installation on any of these platforms is meant to be seamless, without any C/C++ compilation required.

npm install @confluentinc/kafka-javascript

In case your system configuration is not within the supported ones, check the detailed installation instructions for more information.

Yarn and pnpm support is experimental.

Getting Started

Below is a simple produce example using the promisified API.

const { Kafka } = require('@confluentinc/kafka-javascript').KafkaJS;

async function producerStart() {
    const producer = new Kafka().producer({
        'bootstrap.servers': '<fill>',
        'security.protocol': 'SASL_SSL',
        'sasl.mechanisms': 'PLAIN',
        'sasl.username': '<fill>',
        'sasl.password': '<fill>',
    });

    await producer.connect();
    console.log("Connected successfully");

    const res = []
    for (let i = 0; i < 50; i++) {
        res.push(producer.send({
            topic: 'test-topic',
            messages: [
                { value: 'v', partition: 0, key: 'x' },
            ]
        }));
    }
    await Promise.all(res);

    await producer.disconnect();
    console.log("Disconnected successfully");
}

producerStart();

There are two variants of the API offered by this library. A promisified API and a callback-based API.

  1. If you're starting afresh, you should use the promisified API.
  2. If you're migrating from kafkajs, you can use the migration guide to get started quickly.
  3. If you're migrating from node-rdkafka, you can use the migration guide.

An in-depth reference may be found at INTRODUCTION.md.

Contributing

Bug reports and feedback is appreciated in the form of Github Issues. For guidelines on contributing please see CONTRIBUTING.md

Librdkafka Version

| confluent-kafka-javascript | librdkafka | | -------------------------- | ---------- | | 1.0.0 | 2.6.1 |

This mapping is applicable if you're using a pre-built binary. Otherwise, you can check the librdkafka version with the following command:

node -e 'console.log(require("@confluentinc/kafka-javascript").librdkafkaVersion)'