kafka-crab-js 0.1.0 → 0.1.2
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 +9 -8
- package/package.json +4 -4
- package/src/kafka/kafka_client.rs +2 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Kafka Crab Js
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
🚧 Project in Alpha Stage: API Subject to Breaking Changes 🚧
|
|
4
4
|
|
|
5
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.
|
|
6
6
|
|
|
@@ -37,11 +37,11 @@ const kafkaClient = new KafkaClient({
|
|
|
37
37
|
The producer component allows you to send messages to Kafka topics.
|
|
38
38
|
|
|
39
39
|
```javascript
|
|
40
|
+
const producer = kafkaClient.createProducer({topic: 'my-topic'});
|
|
41
|
+
|
|
40
42
|
const result = await producer.send({
|
|
41
43
|
topic: 'my-js-topic',
|
|
42
|
-
|
|
43
|
-
value: Buffer.from(`{"name":"Elizeu Drummond","phone":"55219123456"}`),
|
|
44
|
-
headers: {key: Buffer.from('value1')},
|
|
44
|
+
messages: [{value: Buffer.from(`{"name":"Elizeu Drummond","phone":"55219123456"}`)}],
|
|
45
45
|
});
|
|
46
46
|
console.log('Message sent with offset:', result);
|
|
47
47
|
```
|
|
@@ -55,8 +55,8 @@ Create a consumer instance by specifying the Kafka broker(s), group ID, and othe
|
|
|
55
55
|
|
|
56
56
|
```javascript
|
|
57
57
|
const consumer = kafkaClient.createConsumer({
|
|
58
|
-
topic: 'my-
|
|
59
|
-
groupId: 'my-
|
|
58
|
+
topic: 'my-topic',
|
|
59
|
+
groupId: 'my-group',
|
|
60
60
|
retryStrategy: {
|
|
61
61
|
retries: 3,
|
|
62
62
|
},
|
|
@@ -66,9 +66,10 @@ const consumer = kafkaClient.createConsumer({
|
|
|
66
66
|
You can consume messages using the run startConsumer:
|
|
67
67
|
|
|
68
68
|
```javascript
|
|
69
|
-
consumer.startConsumer(async (error, value) => {
|
|
69
|
+
consumer.startConsumer(async (error, {value, partition, offset}) => {
|
|
70
70
|
const message = JSON.parse(value.toString());
|
|
71
|
-
|
|
71
|
+
console.log('Message received! Partition:', partition, 'Offset:', offset, 'Message =>', message.toString());
|
|
72
|
+
|
|
72
73
|
return ConsumerResult.Ok;
|
|
73
74
|
});
|
|
74
75
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kafka-crab-js",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"napi": {
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
},
|
|
56
56
|
"packageManager": "yarn@3.6.0",
|
|
57
57
|
"optionalDependencies": {
|
|
58
|
-
"kafka-crab-js-darwin-arm64": "0.1.
|
|
59
|
-
"kafka-crab-js-darwin-x64": "0.1.
|
|
60
|
-
"kafka-crab-js-linux-x64-gnu": "0.1.
|
|
58
|
+
"kafka-crab-js-darwin-arm64": "0.1.2",
|
|
59
|
+
"kafka-crab-js-darwin-x64": "0.1.2",
|
|
60
|
+
"kafka-crab-js-linux-x64-gnu": "0.1.2"
|
|
61
61
|
}
|
|
62
62
|
}
|
|
@@ -10,6 +10,7 @@ use rdkafka::{
|
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
use tracing::info;
|
|
13
|
+
use tracing_subscriber::EnvFilter;
|
|
13
14
|
|
|
14
15
|
use super::{
|
|
15
16
|
kafka_consumer::{ConsumerConfiguration, KafkaConsumer},
|
|
@@ -78,7 +79,7 @@ impl KafkaClient {
|
|
|
78
79
|
pub fn new(kafka_configuration: KafkaConfiguration) -> Self {
|
|
79
80
|
match tracing_subscriber::fmt()
|
|
80
81
|
.with_ansi(kafka_configuration.enable_ansi_logger.unwrap_or(false))
|
|
81
|
-
.with_env_filter(
|
|
82
|
+
.with_env_filter(EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")))
|
|
82
83
|
.try_init()
|
|
83
84
|
{
|
|
84
85
|
Ok(_) => {}
|