kafkajs vs kafka-node vs node-rdkafka
Kafkaクライアントライブラリ
kafkajskafka-nodenode-rdkafka

Kafkaクライアントライブラリ

Kafkaクライアントライブラリは、Node.jsアプリケーションがApache Kafkaと通信するためのツールです。これらのライブラリは、メッセージの送受信、トピックの管理、パーティションの操作など、Kafkaの機能をプログラムから利用できるようにします。kafka-nodeはシンプルで使いやすいライブラリで、基本的なKafka操作に適しています。kafkajsはモダンで高性能なライブラリで、TypeScriptサポートやトランザクション機能など、より高度な機能を提供します。node-rdkafkaはC/C++で実装された高性能なクライアントで、低レイテンシーと高スループットが求められるアプリケーションに適しています。

npmのダウンロードトレンド

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
kafkajs2,339,2753,986732 kB3953年前MIT
kafka-node149,3822,661-4486年前MIT
node-rdkafka98,5102,20414.8 MB1253ヶ月前MIT

機能比較: kafkajs vs kafka-node vs node-rdkafka

パフォーマンス

  • kafkajs:

    kafkajsはパフォーマンスに優れており、非同期処理を効果的に活用しています。特にトランザクションやバッチ処理において効率的であり、中規模から大規模のアプリケーションに適しています。

  • kafka-node:

    kafka-nodeは純粋なJavaScriptで実装されており、基本的なパフォーマンスを提供しますが、高負荷環境では限界があります。小規模から中規模のアプリケーションに適しています。

  • node-rdkafka:

    node-rdkafkaはC/C++で実装されたネイティブクライアントを使用しており、低レイテンシーと高スループットを提供します。リアルタイム処理や高負荷環境に最適です。

機能セット

  • kafkajs:

    kafkajsはトランザクション、再試行、スキーマ管理などの高度な機能を提供します。これにより、より複雑なアプリケーションやエンタープライズレベルのソリューションに対応できます。

  • kafka-node:

    kafka-nodeは基本的なプロデューサーとコンシューマー機能を提供しますが、トランザクションや高度な機能はサポートしていません。シンプルなメッセージングアプリケーションに適しています。

  • node-rdkafka:

    node-rdkafkaは高性能なプロデューサーとコンシューマー機能を提供し、トランザクションやパーティション管理などの高度な機能もサポートしています。特にパフォーマンスが重要なアプリケーションに適しています。

セットアップと依存関係

  • kafkajs:

    kafkajsも純粋なJavaScriptで実装されており、セットアップが容易です。TypeScriptサポートが組み込まれているため、型安全な開発が可能です。

  • kafka-node:

    kafka-nodeは純粋なJavaScriptライブラリであり、セットアップが簡単です。追加のネイティブ依存関係はありません。

  • node-rdkafka:

    node-rdkafkaはネイティブモジュールであり、セットアップにはC/C++のビルド環境が必要です。これにより、インストールが複雑になることがありますが、パフォーマンスの利点があります。

コード例

  • kafkajs:

    kafkajsを使用したトランザクションプロデューサーの例です。

  • kafka-node:

    kafka-nodeを使用したシンプルなプロデューサーとコンシューマーの例です。

  • node-rdkafka:

    node-rdkafkaを使用した高性能プロデューサーとコンシューマーの例です。

選び方: kafkajs vs kafka-node vs node-rdkafka

  • kafkajs:

    モダンな設計と高性能を求める場合はkafkajsが適しています。TypeScriptサポートやトランザクション機能など、より高度な機能が必要な場合に特におすすめです。

  • kafka-node:

    基本的なKafka操作を行いたい場合や、シンプルで使いやすいライブラリを求めている場合はkafka-nodeを選択してください。ドキュメントも充実しており、初心者にも扱いやすいです。

  • node-rdkafka:

    低レイテンシーと高スループットが求められるアプリケーションや、C/C++で実装されたネイティブクライアントのパフォーマンスを活用したい場合はnode-rdkafkaを選択してください。ただし、ネイティブモジュールのビルドが必要なため、セットアップに時間がかかることがあります。

kafkajs の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.