Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/inaiat/kafka-crab-js
https://github.com/inaiat/kafka-crab-js
Last synced: 19 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/inaiat/kafka-crab-js
- Owner: inaiat
- Created: 2023-06-16T17:16:28.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-08-20T14:21:03.000Z (3 months ago)
- Last Synced: 2024-10-12T03:09:16.906Z (about 1 month ago)
- Language: Rust
- Size: 2.08 MB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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](https://www.npmjs.com/package/kafka-crab-js) and the source code is available on [GitHub](https://github.com/inaiat/kafka-crab-js).
## Table of Contents
1. [Installation](#installation)
2. [Usage](#usage)
- [Client](#client)
- [Producer](#producer)
- [Consumer](#consumer)
3. [Examples](#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:```shell
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:```javascript
import { KafkaClient }const kafkaClient = new KafkaClient({
brokers: 'localhost:29092',
clientId: 'my-id'});
```
### Producer
The producer component allows you to send messages to Kafka topics.```javascript
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:
```javascript
const consumer = kafkaClient.createConsumer({
topic: 'my-topic',
groupId: 'my-group',
retryStrategy: {
retries: 3,
},
});
```You can consume messages using the run startConsumer:
```javascript
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](https://github.com/inaiat/kafka-crab-js).