kafka-crab-js 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +68 -7
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,16 +1,77 @@
|
|
|
1
|
-
Kafka Crab Js
|
|
2
|
-
-------------
|
|
1
|
+
# Kafka Crab Js
|
|
3
2
|
|
|
4
3
|
**Blazingly Fast Kafka Client for NodeJs**
|
|
5
4
|
|
|
6
5
|
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.
|
|
7
6
|
|
|
7
|
+
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).
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
## Table of Contents
|
|
10
|
+
1. [Installation](#installation)
|
|
11
|
+
2. [Usage](#usage)
|
|
12
|
+
- [Client](#client)
|
|
13
|
+
- [Producer](#producer)
|
|
14
|
+
- [Consumer](#consumer)
|
|
15
|
+
3. [Examples](#examples)
|
|
10
16
|
|
|
11
|
-
To use Kafka-Crab-JS in your Node.js project, follow the steps below:
|
|
12
17
|
|
|
13
|
-
|
|
18
|
+
## Installation
|
|
19
|
+
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:
|
|
14
20
|
|
|
15
|
-
|
|
16
|
-
|
|
21
|
+
```shell
|
|
22
|
+
npm install kafka-crab-js
|
|
23
|
+
```
|
|
24
|
+
## Usage
|
|
25
|
+
### Client
|
|
26
|
+
Creating a Client Instance
|
|
27
|
+
Next, you can create a client instance by specifying the Kafka broker(s) and other optional configurations:
|
|
28
|
+
|
|
29
|
+
```javascript
|
|
30
|
+
import { KafkaClient }
|
|
31
|
+
|
|
32
|
+
const kafkaClient = new KafkaClient({
|
|
33
|
+
brokers: 'localhost:29092',
|
|
34
|
+
clientId: 'my-id'});
|
|
35
|
+
```
|
|
36
|
+
### Producer
|
|
37
|
+
The producer component allows you to send messages to Kafka topics.
|
|
38
|
+
|
|
39
|
+
```javascript
|
|
40
|
+
const result = await producer.send({
|
|
41
|
+
topic: 'my-js-topic',
|
|
42
|
+
key: Buffer.from('abc'),
|
|
43
|
+
value: Buffer.from(`{"name":"Elizeu Drummond","phone":"55219123456"}`),
|
|
44
|
+
headers: {key: Buffer.from('value1')},
|
|
45
|
+
});
|
|
46
|
+
console.log('Message sent with offset:', result);
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
### Consumer
|
|
51
|
+
|
|
52
|
+
**Creating a Consumer Instance**
|
|
53
|
+
|
|
54
|
+
Create a consumer instance by specifying the Kafka broker(s), group ID, and other optional configurations:
|
|
55
|
+
|
|
56
|
+
```javascript
|
|
57
|
+
const consumer = kafkaClient.createConsumer({
|
|
58
|
+
topic: 'my-js-topic',
|
|
59
|
+
groupId: 'my-js-group',
|
|
60
|
+
retryStrategy: {
|
|
61
|
+
retries: 3,
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
You can consume messages using the run startConsumer:
|
|
67
|
+
|
|
68
|
+
```javascript
|
|
69
|
+
consumer.startConsumer(async (error, value) => {
|
|
70
|
+
const message = JSON.parse(value.toString());
|
|
71
|
+
const content = await process_my_message(message);
|
|
72
|
+
return ConsumerResult.Ok;
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
## Examples
|
|
76
|
+
|
|
77
|
+
You can find examples of using Kafka Crab JS in the [GitHub repository](https://github.com/inaiat/kafka-crab-js).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kafka-crab-js",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"napi": {
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
},
|
|
51
51
|
"packageManager": "yarn@3.6.0",
|
|
52
52
|
"optionalDependencies": {
|
|
53
|
-
"kafka-crab-js-darwin-arm64": "0.0.
|
|
54
|
-
"kafka-crab-js-darwin-x64": "0.0.
|
|
55
|
-
"kafka-crab-js-linux-x64-gnu": "0.0.
|
|
53
|
+
"kafka-crab-js-darwin-arm64": "0.0.10",
|
|
54
|
+
"kafka-crab-js-darwin-x64": "0.0.10",
|
|
55
|
+
"kafka-crab-js-linux-x64-gnu": "0.0.10"
|
|
56
56
|
}
|
|
57
57
|
}
|