kafka-crab-js 0.4.1 → 0.5.4
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/.yarnrc.yml +5 -1
- package/Cargo.toml +4 -4
- package/example/sample.mjs +5 -2
- package/index.d.ts +4 -3
- package/index.js +43 -0
- package/package.json +13 -12
- package/src/kafka/consumer/kafka_consumer.rs +1 -1
- package/src/kafka/kafka_client.rs +6 -0
- package/src/kafka/model.rs +1 -3
package/.yarnrc.yml
CHANGED
package/Cargo.toml
CHANGED
|
@@ -8,21 +8,20 @@ crate-type = ["cdylib"]
|
|
|
8
8
|
|
|
9
9
|
[dependencies]
|
|
10
10
|
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
|
|
11
|
-
napi = { version = "2", default-features = false, features = [
|
|
11
|
+
napi = { version = "2.16", default-features = false, features = [
|
|
12
12
|
"napi8",
|
|
13
13
|
"tokio_rt",
|
|
14
14
|
"serde-json",
|
|
15
15
|
] }
|
|
16
|
-
napi-derive = "2"
|
|
16
|
+
napi-derive = "2.16"
|
|
17
17
|
|
|
18
18
|
anyhow = { version = "1.0", features = ["backtrace"] }
|
|
19
19
|
|
|
20
|
-
rdkafka = { version = "0.
|
|
20
|
+
rdkafka = { version = "0.36", features = [
|
|
21
21
|
"libz-static",
|
|
22
22
|
"cmake-build",
|
|
23
23
|
"tokio",
|
|
24
24
|
"ssl-vendored",
|
|
25
|
-
"ssl",
|
|
26
25
|
] }
|
|
27
26
|
tokio = { version = "1", features = ["full"] }
|
|
28
27
|
|
|
@@ -34,3 +33,4 @@ napi-build = "2.0.1"
|
|
|
34
33
|
|
|
35
34
|
[profile.release]
|
|
36
35
|
lto = true
|
|
36
|
+
strip = "symbols"
|
package/example/sample.mjs
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
/* eslint-disable no-await-in-loop */
|
|
2
2
|
|
|
3
|
-
import timersPromises from 'node:timers/promises';
|
|
3
|
+
// import timersPromises from 'node:timers/promises';
|
|
4
4
|
import { Buffer } from 'node:buffer';
|
|
5
5
|
import { nanoid } from 'nanoid';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
KafkaClient, CommitMode, PartitionPosition, ConsumerResult,
|
|
8
|
+
} from '../index.js';
|
|
7
9
|
|
|
8
10
|
const kafkaClient = new KafkaClient({
|
|
9
11
|
brokers: 'localhost:29092',
|
|
10
12
|
clientId: 'my-js-group',
|
|
11
13
|
logLevel: 'info',
|
|
14
|
+
brokerAddressFamily: 'v4',
|
|
12
15
|
});
|
|
13
16
|
const topic = `topic-${nanoid()}`;
|
|
14
17
|
|
package/index.d.ts
CHANGED
|
@@ -42,6 +42,7 @@ export interface KafkaConfiguration {
|
|
|
42
42
|
securityProtocol?: SecurityProtocol
|
|
43
43
|
configuration?: Record<string, string>
|
|
44
44
|
logLevel?: string
|
|
45
|
+
brokerAddressFamily?: string
|
|
45
46
|
}
|
|
46
47
|
export interface ProducerConfiguration {
|
|
47
48
|
queueTimeout?: number
|
|
@@ -70,9 +71,9 @@ export interface Payload {
|
|
|
70
71
|
offset: number
|
|
71
72
|
}
|
|
72
73
|
export const enum PartitionPosition {
|
|
73
|
-
Beginning =
|
|
74
|
-
End =
|
|
75
|
-
Stored =
|
|
74
|
+
Beginning = 'Beginning',
|
|
75
|
+
End = 'End',
|
|
76
|
+
Stored = 'Stored'
|
|
76
77
|
}
|
|
77
78
|
export interface OffsetModel {
|
|
78
79
|
offset?: number
|
package/index.js
CHANGED
|
@@ -237,6 +237,49 @@ switch (platform) {
|
|
|
237
237
|
loadError = e
|
|
238
238
|
}
|
|
239
239
|
break
|
|
240
|
+
case 'riscv64':
|
|
241
|
+
if (isMusl()) {
|
|
242
|
+
localFileExisted = existsSync(
|
|
243
|
+
join(__dirname, 'kafka-crab-js.linux-riscv64-musl.node')
|
|
244
|
+
)
|
|
245
|
+
try {
|
|
246
|
+
if (localFileExisted) {
|
|
247
|
+
nativeBinding = require('./kafka-crab-js.linux-riscv64-musl.node')
|
|
248
|
+
} else {
|
|
249
|
+
nativeBinding = require('kafka-crab-js-linux-riscv64-musl')
|
|
250
|
+
}
|
|
251
|
+
} catch (e) {
|
|
252
|
+
loadError = e
|
|
253
|
+
}
|
|
254
|
+
} else {
|
|
255
|
+
localFileExisted = existsSync(
|
|
256
|
+
join(__dirname, 'kafka-crab-js.linux-riscv64-gnu.node')
|
|
257
|
+
)
|
|
258
|
+
try {
|
|
259
|
+
if (localFileExisted) {
|
|
260
|
+
nativeBinding = require('./kafka-crab-js.linux-riscv64-gnu.node')
|
|
261
|
+
} else {
|
|
262
|
+
nativeBinding = require('kafka-crab-js-linux-riscv64-gnu')
|
|
263
|
+
}
|
|
264
|
+
} catch (e) {
|
|
265
|
+
loadError = e
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
break
|
|
269
|
+
case 's390x':
|
|
270
|
+
localFileExisted = existsSync(
|
|
271
|
+
join(__dirname, 'kafka-crab-js.linux-s390x-gnu.node')
|
|
272
|
+
)
|
|
273
|
+
try {
|
|
274
|
+
if (localFileExisted) {
|
|
275
|
+
nativeBinding = require('./kafka-crab-js.linux-s390x-gnu.node')
|
|
276
|
+
} else {
|
|
277
|
+
nativeBinding = require('kafka-crab-js-linux-s390x-gnu')
|
|
278
|
+
}
|
|
279
|
+
} catch (e) {
|
|
280
|
+
loadError = e
|
|
281
|
+
}
|
|
282
|
+
break
|
|
240
283
|
default:
|
|
241
284
|
throw new Error(`Unsupported architecture on Linux: ${arch}`)
|
|
242
285
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kafka-crab-js",
|
|
3
|
-
"version": "0.4
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"napi": {
|
|
@@ -24,19 +24,20 @@
|
|
|
24
24
|
],
|
|
25
25
|
"author": "inaiat@gmail.com",
|
|
26
26
|
"homepage": "https://github.com/inaiat/kafka-crab-js.git",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "https://github.com/inaiat/kafka-crab-js.git"
|
|
30
|
+
},
|
|
27
31
|
"devDependencies": {
|
|
28
|
-
"@napi-rs/cli": "^2.
|
|
29
|
-
"ava": "^
|
|
30
|
-
"
|
|
31
|
-
"kafkajs": "^2.2.4",
|
|
32
|
-
"nanoid": "^4.0.2",
|
|
33
|
-
"xo": "^0.54.2"
|
|
32
|
+
"@napi-rs/cli": "^2.18.0",
|
|
33
|
+
"ava": "^6.1.2",
|
|
34
|
+
"xo": "^0.58.0"
|
|
34
35
|
},
|
|
35
36
|
"ava": {
|
|
36
37
|
"timeout": "3m"
|
|
37
38
|
},
|
|
38
39
|
"engines": {
|
|
39
|
-
"node": ">=
|
|
40
|
+
"node": ">= 18"
|
|
40
41
|
},
|
|
41
42
|
"xo": {
|
|
42
43
|
"space": true,
|
|
@@ -54,10 +55,10 @@
|
|
|
54
55
|
"universal": "napi universal",
|
|
55
56
|
"version": "napi version"
|
|
56
57
|
},
|
|
57
|
-
"packageManager": "yarn@
|
|
58
|
+
"packageManager": "yarn@4.1.1",
|
|
58
59
|
"optionalDependencies": {
|
|
59
|
-
"kafka-crab-js-darwin-arm64": "0.4
|
|
60
|
-
"kafka-crab-js-darwin-x64": "0.4
|
|
61
|
-
"kafka-crab-js-linux-x64-gnu": "0.4
|
|
60
|
+
"kafka-crab-js-darwin-arm64": "0.5.4",
|
|
61
|
+
"kafka-crab-js-darwin-x64": "0.5.4",
|
|
62
|
+
"kafka-crab-js-linux-x64-gnu": "0.5.4"
|
|
62
63
|
}
|
|
63
64
|
}
|
|
@@ -62,6 +62,7 @@ pub struct KafkaConfiguration {
|
|
|
62
62
|
pub security_protocol: Option<SecurityProtocol>,
|
|
63
63
|
pub configuration: Option<HashMap<String, String>>,
|
|
64
64
|
pub log_level: Option<String>,
|
|
65
|
+
pub broker_address_family: Option<String>,
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
#[derive(Clone, Debug)]
|
|
@@ -103,6 +104,7 @@ impl KafkaClient {
|
|
|
103
104
|
security_protocol,
|
|
104
105
|
client_id,
|
|
105
106
|
configuration,
|
|
107
|
+
broker_address_family,
|
|
106
108
|
..
|
|
107
109
|
} = kafka_configuration.clone();
|
|
108
110
|
|
|
@@ -111,6 +113,10 @@ impl KafkaClient {
|
|
|
111
113
|
rdkafka_client_config.set_log_level(RDKafkaLogLevel::Debug);
|
|
112
114
|
rdkafka_client_config.set("bootstrap.servers", brokers);
|
|
113
115
|
rdkafka_client_config.set("client.id", client_id);
|
|
116
|
+
rdkafka_client_config.set(
|
|
117
|
+
"broker.address.family",
|
|
118
|
+
broker_address_family.unwrap_or("v4".to_string()),
|
|
119
|
+
);
|
|
114
120
|
if let Some(security_protocol) = security_protocol {
|
|
115
121
|
rdkafka_client_config.set("security.protocol", security_protocol.to_string());
|
|
116
122
|
}
|
package/src/kafka/model.rs
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
use napi::bindgen_prelude::*;
|
|
2
|
-
|
|
3
1
|
use std::{collections::HashMap, fmt};
|
|
4
2
|
|
|
5
3
|
use napi::bindgen_prelude::Buffer;
|
|
@@ -53,7 +51,7 @@ impl Payload {
|
|
|
53
51
|
}
|
|
54
52
|
}
|
|
55
53
|
|
|
56
|
-
#[napi(
|
|
54
|
+
#[napi(string_enum)]
|
|
57
55
|
#[derive(Debug)]
|
|
58
56
|
pub enum PartitionPosition {
|
|
59
57
|
Beginning,
|