kafka-crab-js 0.2.0 → 0.3.0
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 +0 -2
- package/example/sample.mjs +10 -10
- package/index.d.ts +1 -1
- package/package.json +6 -5
- package/src/kafka/kafka_consumer.rs +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# Kafka Crab Js
|
|
2
2
|
|
|
3
|
-
🚧 Project in Alpha Stage: API Subject to Breaking Changes 🚧
|
|
4
|
-
|
|
5
3
|
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.
|
|
6
4
|
|
|
7
5
|
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).
|
package/example/sample.mjs
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
/* eslint-disable no-await-in-loop */
|
|
2
2
|
|
|
3
3
|
import timersPromises from 'node:timers/promises';
|
|
4
|
-
import {Buffer} from 'node:buffer';
|
|
5
|
-
import {nanoid} from 'nanoid';
|
|
6
|
-
import {KafkaClient, CommitMode, PartitionPosition, ConsumerResult} from '../index.js';
|
|
4
|
+
import { Buffer } from 'node:buffer';
|
|
5
|
+
import { nanoid } from 'nanoid';
|
|
6
|
+
import { KafkaClient, CommitMode, PartitionPosition, ConsumerResult } from '../index.js';
|
|
7
7
|
|
|
8
8
|
const kafkaClient = new KafkaClient({
|
|
9
9
|
brokers: 'localhost:29092',
|
|
10
10
|
clientId: 'my-js-group',
|
|
11
11
|
logLevel: 'info',
|
|
12
|
-
|
|
12
|
+
});
|
|
13
13
|
const topic = `topic-${nanoid()}`;
|
|
14
14
|
|
|
15
15
|
const consumer = kafkaClient.createConsumer({
|
|
16
16
|
topic,
|
|
17
17
|
groupId: 'my-js-group',
|
|
18
|
-
|
|
19
|
-
offset: {position: PartitionPosition.Stored},
|
|
20
|
-
configuration: {'auto.offset.reset': 'earliest'},
|
|
18
|
+
commitMode: CommitMode.AutoCommit,
|
|
19
|
+
offset: { position: PartitionPosition.Stored },
|
|
20
|
+
configuration: { 'auto.offset.reset': 'earliest' },
|
|
21
21
|
retryStrategy: {
|
|
22
22
|
retries: 5,
|
|
23
23
|
pauseConsumerDuration: 5000,
|
|
24
24
|
},
|
|
25
25
|
});
|
|
26
|
-
const producer = kafkaClient.createProducer({topic, configuration: {'message.timeout.ms': '5000'}});
|
|
26
|
+
const producer = kafkaClient.createProducer({ topic, configuration: { 'message.timeout.ms': '5000' } });
|
|
27
27
|
|
|
28
28
|
async function produce() {
|
|
29
29
|
for (let i = 0; i < 10; i++) {
|
|
@@ -31,7 +31,7 @@ async function produce() {
|
|
|
31
31
|
const result = await producer.send(
|
|
32
32
|
{
|
|
33
33
|
topic,
|
|
34
|
-
messages: [{value: Buffer.from(`{"_id":"${i}","name":"Elizeu Drummond Sample js","phone":"555"}`)}],
|
|
34
|
+
messages: [{ value: Buffer.from(`{"_id":"${i}","name":"Elizeu Drummond Sample js","phone":"555"}`) }],
|
|
35
35
|
},
|
|
36
36
|
);
|
|
37
37
|
console.log('Js message sent. Offset:', result);
|
|
@@ -42,7 +42,7 @@ async function produce() {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
async function startConsumer() {
|
|
45
|
-
consumer.startConsumer(async (error, {value, partition, offset}) => {
|
|
45
|
+
consumer.startConsumer(async (error, { value, partition, offset }) => {
|
|
46
46
|
if (error) {
|
|
47
47
|
console.error('Js Consumer error', error);
|
|
48
48
|
return;
|
package/index.d.ts
CHANGED
|
@@ -101,7 +101,7 @@ export class KafkaClient {
|
|
|
101
101
|
}
|
|
102
102
|
export class ProducerHelper { }
|
|
103
103
|
export class KafkaConsumer {
|
|
104
|
-
startConsumer(callback: (
|
|
104
|
+
startConsumer(callback: (error: Error | undefined, result: Payload) => Promise<ConsumerResult | undefined>): Promise<void>
|
|
105
105
|
}
|
|
106
106
|
export class KafkaProducer {
|
|
107
107
|
send(producerRecord: ProducerRecord): Promise<Array<RecordMetadata>>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kafka-crab-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"napi": {
|
|
@@ -41,7 +41,8 @@
|
|
|
41
41
|
"xo": {
|
|
42
42
|
"space": true,
|
|
43
43
|
"rules": {
|
|
44
|
-
"new-cap": "off"
|
|
44
|
+
"new-cap": "off",
|
|
45
|
+
"object-curly-spacing": "off"
|
|
45
46
|
}
|
|
46
47
|
},
|
|
47
48
|
"scripts": {
|
|
@@ -55,8 +56,8 @@
|
|
|
55
56
|
},
|
|
56
57
|
"packageManager": "yarn@3.6.0",
|
|
57
58
|
"optionalDependencies": {
|
|
58
|
-
"kafka-crab-js-darwin-arm64": "0.
|
|
59
|
-
"kafka-crab-js-darwin-x64": "0.
|
|
60
|
-
"kafka-crab-js-linux-x64-gnu": "0.
|
|
59
|
+
"kafka-crab-js-darwin-arm64": "0.3.0",
|
|
60
|
+
"kafka-crab-js-darwin-x64": "0.3.0",
|
|
61
|
+
"kafka-crab-js-linux-x64-gnu": "0.3.0"
|
|
61
62
|
}
|
|
62
63
|
}
|
|
@@ -150,7 +150,7 @@ impl KafkaConsumer {
|
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
#[napi(
|
|
153
|
-
ts_args_type = "callback: (
|
|
153
|
+
ts_args_type = "callback: (error: Error | undefined, result: Payload) => Promise<ConsumerResult | undefined>"
|
|
154
154
|
)]
|
|
155
155
|
pub async fn start_consumer(&self, func: ThreadsafeFunction<Payload>) -> Result<()> {
|
|
156
156
|
let ConsumerConfiguration { retry_strategy, .. } = self.consumer_configuration.clone();
|