0.5.4 • Published 1 month ago

kafka-crab-js v0.5.4

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

Kafka Crab Js

Kafka-Crab-JS is a powerful Node.js library that allows developers to interact with Apache Kafka using Rust programming language, seamlessly integrated with Node.js applications. This documentation provides an overview of the Kafka-Crab-JS library, including installation instructions, usage guidelines, and examples.

The plugin can be found on npm and the source code is available on GitHub.

Table of Contents

  1. Installation
  2. Usage
  3. Examples

Installation

To use Kafka Crab JS, you need to have Node.js and npm (Node Package Manager) installed on your system. Once you have them set up, you can install the plugin by running the following command:

npm install kafka-crab-js

Usage

Client

Creating a Client Instance Next, you can create a client instance by specifying the Kafka broker(s) and other optional configurations:

import { KafkaClient }

const kafkaClient = new KafkaClient({
  brokers: 'localhost:29092',
  clientId: 'my-id'});

Producer

The producer component allows you to send messages to Kafka topics.

const producer = kafkaClient.createProducer({topic: 'my-topic'});

const result = await producer.send({
    topic: 'my-js-topic',
    messages: [{value: Buffer.from(`{"name":"Elizeu Drummond","phone":"55219123456"}`)}],
});
console.log('Message sent with offset:', result);

Consumer

Creating a Consumer Instance

Create a consumer instance by specifying the Kafka broker(s), group ID, and other optional configurations:

const consumer = kafkaClient.createConsumer({
  topic: 'my-topic',
  groupId: 'my-group',
  retryStrategy: {
    retries: 3,
  },
});

You can consume messages using the run startConsumer:

consumer.startConsumer(async (error, {value, partition, offset}) => {
  const message = JSON.parse(value.toString());
  console.log('Message received! Partition:', partition, 'Offset:', offset, 'Message =>', message.toString());

  return ConsumerResult.Ok;
});

Examples

You can find examples of using Kafka Crab JS in the GitHub repository.

0.5.4

1 month ago

0.4.1

8 months ago

0.3.1

8 months ago

0.3.0

9 months ago

0.2.0

10 months ago

0.1.2

10 months ago

0.1.1

10 months ago

0.1.0

10 months ago

0.0.10

11 months ago

0.0.9

11 months ago

0.0.3

11 months ago

0.0.2

11 months ago

0.0.0

11 months ago