kafkajs vs kafka-node vs node-rdkafka
Kafka Kütüphaneleri
kafkajskafka-nodenode-rdkafka

Kafka Kütüphaneleri

Kafka, yüksek hacimli veri akışlarını işlemek için kullanılan dağıtık bir mesajlaşma sistemidir. Node.js ekosisteminde Kafka ile etkileşim kurmak için çeşitli kütüphaneler bulunmaktadır. Bu kütüphaneler, Kafka'ya veri göndermek (producer) ve Kafka'dan veri almak (consumer) için API'ler sağlar. kafka-node, Kafka ile etkileşim kurmak için temel bir kütüphane olup, basit ve kullanımı kolaydır. kafkajs, modern ve tamamen JavaScript ile yazılmış bir Kafka istemcisidir. Performans ve kullanım kolaylığına odaklanmıştır. node-rdkafka, C++ ile yazılmış yüksek performanslı bir Kafka istemcisidir ve özellikle düşük gecikme ve yüksek verim gerektiren uygulamalar için uygundur.

npm İndirme Trendi

3 Yıl

GitHub Stars Sıralaması

İstatistik Detayı

Paket
İndirmeler
Stars
Boyut
Issues
Yayın Tarihi
Lisans
kafkajs4,772,1093,998732 kB418il y a 4 ansMIT
kafka-node140,5652,647-442il y a 7 ansMIT
node-rdkafka75,1702,21014.8 MB131il y a un anMIT

Özellik Karşılaştırması: kafkajs vs kafka-node vs node-rdkafka

Performans

  • kafkajs:

    kafkajs, performans ve verimlilik açısından optimize edilmiştir ve özellikle orta ölçekli uygulamalar için idealdir.

  • kafka-node:

    kafka-node performansı, basit Kafka işlemleri için yeterlidir ancak yüksek hacimli veri akışlarında sınırlamalar olabilir.

  • node-rdkafka:

    node-rdkafka, C++ ile yazıldığı için en yüksek performansı sunar ve büyük veri akışları için uygundur.

Kurulum ve Kullanım Kolaylığı

  • kafkajs:

    kafkajs modern bir API sunar ve kullanımı kolaydır. Dokümantasyonu da oldukça iyidir.

  • kafka-node:

    kafka-node kurulumu ve kullanımı oldukça basittir. Özellikle hızlı entegrasyon için uygundur.

  • node-rdkafka:

    node-rdkafka yüksek performanslıdır ancak C++ bağımlılıkları nedeniyle kurulum süreci daha karmaşıktır.

Özellikler

  • kafkajs:

    kafkajs gelişmiş özellikler sunar ve özellikle modern JavaScript özelliklerini kullanır.

  • kafka-node:

    kafka-node temel Kafka özelliklerini destekler ancak gelişmiş özellikler sınırlıdır.

  • node-rdkafka:

    node-rdkafka Kafka'nın tüm gelişmiş özelliklerini destekler ve özellikle performans odaklıdır.

Topluluk ve Destek

  • kafkajs:

    kafkajs hızla büyüyen bir topluluğa sahiptir ve aktif olarak geliştirilmektedir.

  • kafka-node:

    kafka-node uzun süredir kullanılan bir kütüphane olup, geniş bir topluluğa sahiptir.

  • node-rdkafka:

    node-rdkafka performans odaklı uygulamalarda yaygın olarak kullanılır ve iyi bir topluluk desteğine sahiptir.

Kod Örnekleri

  • kafkajs:

    kafkajs ile basit bir producer ve consumer örneği:

    const { Kafka } = require('kafkajs');
    const kafka = new Kafka({ clientId: 'my-app', brokers: ['localhost:9092'] });
    const producer = kafka.producer();
    const consumer = kafka.consumer({ groupId: 'test-group' });
    
    const run = async () => {
      await producer.connect();
      await consumer.connect();
      await consumer.subscribe({ topic: 'test', fromBeginning: true });
    
      await producer.send({
        topic: 'test',
        messages: [{ value: 'Hello KafkaJS' }],
      });
    
      consumer.run({
        eachMessage: async ({ topic, partition, message }) => {
          console.log(`Received message: ${message.value.toString()}`);
        },
      });
    };
    
    run().catch(console.error);
    
  • kafka-node:

    kafka-node ile basit bir producer ve consumer örneği:

    const kafka = require('kafka-node');
    const Producer = kafka.Producer;
    const Consumer = kafka.Consumer;
    const client = new kafka.KafkaClient({kafkaHost: 'localhost:9092'});
    const producer = new Producer(client);
    const consumer = new Consumer(client, [{ topic: 'test', partition: 0 }], { autoCommit: true });
    
    producer.on('ready', () => {
      producer.send([{ topic: 'test', messages: ['Hello Kafka'] }], (err, data) => {
        if (err) console.error(err);
        else console.log('Message sent:', data);
      });
    });
    
    consumer.on('message', (message) => {
      console.log('Received message:', message);
    });
    
  • node-rdkafka:

    node-rdkafka ile basit bir producer ve consumer örneği:

    const Kafka = require('node-rdkafka');
    const producer = new Kafka.Producer({ 'metadata.broker.list': 'localhost:9092' });
    const consumer = new Kafka.KafkaConsumer({ 'group.id': 'test-group', 'metadata.broker.list': 'localhost:9092' }, {});
    
    producer.on('ready', () => {
      producer.produce('test', null, Buffer.from('Hello node-rdkafka'));
    });
    producer.connect();
    
    consumer.on('ready', () => {
      consumer.subscribe(['test']);
      consumer.consume();
    });
    consumer.on('data', (data) => {
      console.log(`Received message: ${data.value.toString()}`);
    });
    consumer.connect();
    

Nasıl Seçilir: kafkajs vs kafka-node vs node-rdkafka

  • kafkajs:

    Modern ve performanslı bir Kafka istemcisi arıyorsanız kafkajs iyi bir seçimdir. Tamamen JavaScript ile yazılmış olması, özellikle TypeScript projelerinde avantaj sağlar.

  • kafka-node:

    Basit ve temel Kafka işlemleri için kafka-node tercih edilebilir. Özellikle hızlı bir şekilde Kafka ile entegrasyon sağlamak isteyenler için uygundur.

  • node-rdkafka:

    Yüksek performans ve düşük gecikme gerektiren uygulamalar için node-rdkafka tercih edilmelidir. Ancak, C++ bağımlılıkları nedeniyle kurulum ve yapılandırma biraz daha karmaşık olabilir.

kafkajs için README

npm version npm pre-release version Build Status Slack Channel

Logo

KafkaJS

A modern Apache Kafka® client for Node.js
Get Started »

Read the Docs · Report Bug · Request Feature

Table of Contents

About the Project

KafkaJS is a modern Apache Kafka client for Node.js. It is compatible with Kafka 0.10+ and offers native support for 0.11 features.

KAFKA is a registered trademark of The Apache Software Foundation and has been licensed for use by KafkaJS. KafkaJS has no affiliation with and is not endorsed by The Apache Software Foundation.

Sponsors ❤️

Upstash: Serverless Kafka

  • True Serverless Kafka with per-request-pricing
  • Managed Apache Kafka, works with all Kafka clients
  • Built-in REST API designed for serverless and edge functions
  • Start for free in 30 seconds!
Logo

Get help directly from a KafkaJS developer

  • Become a Github Sponsor to have a video call with a KafkaJS developer
  • Receive personalized support, validate ideas or accelerate your learning
  • Save time and get productive sooner, while supporting KafkaJS!
  • See support options!

To become a sponsor, reach out in our Slack community to get in touch with one of the maintainers. Also consider becoming a Github Sponsor by following any of the links under "Sponsor this project" in the sidebar.

Features

  • Producer
  • Consumer groups with pause, resume, and seek
  • Transactional support for producers and consumers
  • Message headers
  • GZIP compression
    • Snappy, LZ4 and ZSTD compression through pluggable codecs
  • Plain, SSL and SASL_SSL implementations
  • Support for SCRAM-SHA-256 and SCRAM-SHA-512
  • Support for AWS IAM authentication
  • Admin client

Getting Started

npm install kafkajs
# yarn add kafkajs

Usage

const { Kafka } = require('kafkajs')

const kafka = new Kafka({
  clientId: 'my-app',
  brokers: ['kafka1:9092', 'kafka2:9092']
})

const producer = kafka.producer()
const consumer = kafka.consumer({ groupId: 'test-group' })

const run = async () => {
  // Producing
  await producer.connect()
  await producer.send({
    topic: 'test-topic',
    messages: [
      { value: 'Hello KafkaJS user!' },
    ],
  })

  // Consuming
  await consumer.connect()
  await consumer.subscribe({ topic: 'test-topic', fromBeginning: true })

  await consumer.run({
    eachMessage: async ({ topic, partition, message }) => {
      console.log({
        partition,
        offset: message.offset,
        value: message.value.toString(),
      })
    },
  })
}

run().catch(console.error)

Learn more about using KafkaJS on the official site!

Read something on the website that didn't work with the latest stable version?
Check the pre-release versions - the website is updated on every merge to master.

Contributing

KafkaJS is an open-source project where development takes place in the open on GitHub. Although the project is maintained by a small group of dedicated volunteers, we are grateful to the community for bug fixes, feature development and other contributions.

See Developing KafkaJS for information on how to run and develop KafkaJS.

Help wanted 🤝

We welcome contributions to KafkaJS, but we also want to see a thriving third-party ecosystem. If you would like to create an open-source project that builds on top of KafkaJS, please get in touch and we'd be happy to provide feedback and support.

Here are some projects that we would like to build, but haven't yet been able to prioritize:

Contact 💬

Join our Slack community

License

See LICENSE for more details.

Acknowledgements

Apache Kafka and Kafka are either registered trademarks or trademarks of The Apache Software Foundation in the United States and other countries. KafkaJS has no affiliation with the Apache Software Foundation.