kafka-ts 0.0.1-beta.4 → 0.0.1-beta.6
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/.github/workflows/release.yml +19 -6
- package/README.md +15 -21
- package/dist/api/api-versions.d.ts +9 -0
- package/dist/api/api-versions.js +24 -0
- package/dist/api/create-topics.d.ts +38 -0
- package/dist/api/create-topics.js +53 -0
- package/dist/api/delete-topics.d.ts +18 -0
- package/dist/api/delete-topics.js +33 -0
- package/dist/api/fetch.d.ts +84 -0
- package/dist/api/fetch.js +142 -0
- package/dist/api/find-coordinator.d.ts +21 -0
- package/dist/api/find-coordinator.js +39 -0
- package/dist/api/heartbeat.d.ts +11 -0
- package/dist/api/heartbeat.js +27 -0
- package/dist/api/index.d.ts +578 -0
- package/dist/api/index.js +165 -0
- package/dist/api/init-producer-id.d.ts +13 -0
- package/dist/api/init-producer-id.js +29 -0
- package/dist/api/join-group.d.ts +34 -0
- package/dist/api/join-group.js +51 -0
- package/dist/api/leave-group.d.ts +19 -0
- package/dist/api/leave-group.js +39 -0
- package/dist/api/list-offsets.d.ts +29 -0
- package/dist/api/list-offsets.js +48 -0
- package/dist/api/metadata.d.ts +40 -0
- package/dist/api/metadata.js +58 -0
- package/dist/api/offset-commit.d.ts +28 -0
- package/dist/api/offset-commit.js +48 -0
- package/dist/api/offset-fetch.d.ts +33 -0
- package/dist/api/offset-fetch.js +57 -0
- package/dist/api/produce.d.ts +54 -0
- package/dist/api/produce.js +126 -0
- package/dist/api/sasl-authenticate.d.ts +11 -0
- package/dist/api/sasl-authenticate.js +23 -0
- package/dist/api/sasl-handshake.d.ts +6 -0
- package/dist/api/sasl-handshake.js +19 -0
- package/dist/api/sync-group.d.ts +24 -0
- package/dist/api/sync-group.js +36 -0
- package/dist/auth/index.d.ts +2 -0
- package/dist/auth/index.js +8 -0
- package/dist/auth/plain.d.ts +5 -0
- package/dist/auth/plain.js +12 -0
- package/dist/auth/scram.d.ts +9 -0
- package/dist/auth/scram.js +40 -0
- package/dist/broker.d.ts +30 -0
- package/dist/broker.js +55 -0
- package/dist/client.d.ts +23 -0
- package/dist/client.js +36 -0
- package/dist/cluster.d.ts +27 -0
- package/dist/cluster.js +70 -0
- package/dist/cluster.test.d.ts +1 -0
- package/dist/cluster.test.js +345 -0
- package/dist/codecs/gzip.d.ts +2 -0
- package/dist/codecs/gzip.js +8 -0
- package/dist/codecs/index.d.ts +2 -0
- package/dist/codecs/index.js +17 -0
- package/dist/codecs/none.d.ts +2 -0
- package/dist/codecs/none.js +7 -0
- package/dist/codecs/types.d.ts +5 -0
- package/dist/codecs/types.js +2 -0
- package/dist/connection.d.ts +26 -0
- package/dist/connection.js +175 -0
- package/dist/consumer/consumer-group.d.ts +41 -0
- package/dist/consumer/consumer-group.js +217 -0
- package/dist/consumer/consumer-metadata.d.ts +7 -0
- package/dist/consumer/consumer-metadata.js +14 -0
- package/dist/consumer/consumer.d.ts +44 -0
- package/dist/consumer/consumer.js +225 -0
- package/dist/consumer/fetch-manager.d.ts +33 -0
- package/dist/consumer/fetch-manager.js +140 -0
- package/dist/consumer/fetcher.d.ts +25 -0
- package/dist/consumer/fetcher.js +64 -0
- package/dist/consumer/offset-manager.d.ts +22 -0
- package/dist/consumer/offset-manager.js +66 -0
- package/dist/consumer/processor.d.ts +19 -0
- package/dist/consumer/processor.js +59 -0
- package/dist/distributors/assignments-to-replicas.d.ts +16 -0
- package/dist/distributors/assignments-to-replicas.js +59 -0
- package/dist/distributors/assignments-to-replicas.test.d.ts +1 -0
- package/dist/distributors/assignments-to-replicas.test.js +40 -0
- package/dist/distributors/messages-to-topic-partition-leaders.d.ts +17 -0
- package/dist/distributors/messages-to-topic-partition-leaders.js +15 -0
- package/dist/distributors/messages-to-topic-partition-leaders.test.d.ts +1 -0
- package/dist/distributors/messages-to-topic-partition-leaders.test.js +30 -0
- package/dist/distributors/partitioner.d.ts +7 -0
- package/dist/distributors/partitioner.js +23 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +26 -0
- package/dist/metadata.d.ts +24 -0
- package/dist/metadata.js +106 -0
- package/dist/producer/producer.d.ts +24 -0
- package/dist/producer/producer.js +131 -0
- package/dist/types.d.ts +11 -0
- package/dist/types.js +2 -0
- package/dist/utils/api.d.ts +9 -0
- package/dist/utils/api.js +5 -0
- package/dist/utils/crypto.d.ts +8 -0
- package/dist/utils/crypto.js +18 -0
- package/dist/utils/decoder.d.ts +30 -0
- package/dist/utils/decoder.js +152 -0
- package/dist/utils/delay.d.ts +1 -0
- package/dist/utils/delay.js +5 -0
- package/dist/utils/encoder.d.ts +28 -0
- package/dist/utils/encoder.js +125 -0
- package/dist/utils/error.d.ts +11 -0
- package/dist/utils/error.js +27 -0
- package/dist/utils/logger.d.ts +9 -0
- package/dist/utils/logger.js +32 -0
- package/dist/utils/memo.d.ts +1 -0
- package/dist/utils/memo.js +16 -0
- package/dist/utils/murmur2.d.ts +3 -0
- package/dist/utils/murmur2.js +40 -0
- package/dist/utils/retrier.d.ts +10 -0
- package/dist/utils/retrier.js +22 -0
- package/dist/utils/tracer.d.ts +5 -0
- package/dist/utils/tracer.js +39 -0
- package/docker-compose.yml +3 -3
- package/examples/package-lock.json +3501 -3
- package/examples/package.json +8 -1
- package/examples/src/benchmark/common.ts +98 -0
- package/examples/src/benchmark/kafka-ts.ts +67 -0
- package/examples/src/benchmark/kafkajs.ts +51 -0
- package/examples/src/client.ts +4 -1
- package/examples/src/opentelemetry.ts +46 -0
- package/examples/src/producer.ts +11 -11
- package/package.json +4 -2
- package/scripts/create-scram-user.sh +4 -2
- package/scripts/generate-certs.sh +2 -0
- package/src/__snapshots__/cluster.test.ts.snap +35 -185
- package/src/api/fetch.ts +6 -1
- package/src/api/index.ts +3 -1
- package/src/api/metadata.ts +1 -1
- package/src/api/produce.ts +7 -10
- package/src/cluster.test.ts +2 -2
- package/src/cluster.ts +9 -16
- package/src/connection.ts +28 -15
- package/src/consumer/consumer-group.ts +35 -15
- package/src/consumer/consumer.ts +28 -18
- package/src/consumer/fetch-manager.ts +29 -45
- package/src/consumer/fetcher.ts +21 -14
- package/src/consumer/offset-manager.ts +18 -7
- package/src/consumer/processor.ts +14 -10
- package/src/distributors/assignments-to-replicas.ts +1 -3
- package/src/index.ts +1 -1
- package/src/metadata.ts +4 -0
- package/src/producer/producer.ts +11 -6
- package/src/utils/decoder.ts +0 -4
- package/src/utils/encoder.ts +26 -19
- package/src/utils/logger.ts +4 -4
- package/src/utils/tracer.ts +39 -23
- package/certs/ca.key +0 -52
- package/certs/ca.srl +0 -1
- package/certs/kafka.crt +0 -29
- package/certs/kafka.csr +0 -26
- package/certs/kafka.key +0 -52
- package/src/utils/mutex.ts +0 -31
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
2
|
|
|
3
|
-
exports[`
|
|
3
|
+
exports[`Low-level API > should commit offsets 1`] = `
|
|
4
4
|
{
|
|
5
5
|
"_tag": undefined,
|
|
6
6
|
"_tag2": undefined,
|
|
@@ -21,7 +21,7 @@ exports[`Request handler > should commit offsets 1`] = `
|
|
|
21
21
|
}
|
|
22
22
|
`;
|
|
23
23
|
|
|
24
|
-
exports[`
|
|
24
|
+
exports[`Low-level API > should create topics 1`] = `
|
|
25
25
|
{
|
|
26
26
|
"_tag": undefined,
|
|
27
27
|
"_tag2": undefined,
|
|
@@ -290,7 +290,7 @@ exports[`Request handler > should create topics 1`] = `
|
|
|
290
290
|
}
|
|
291
291
|
`;
|
|
292
292
|
|
|
293
|
-
exports[`
|
|
293
|
+
exports[`Low-level API > should delete topics 1`] = `
|
|
294
294
|
{
|
|
295
295
|
"_tag": undefined,
|
|
296
296
|
"_tag2": undefined,
|
|
@@ -307,7 +307,7 @@ exports[`Request handler > should delete topics 1`] = `
|
|
|
307
307
|
}
|
|
308
308
|
`;
|
|
309
309
|
|
|
310
|
-
exports[`
|
|
310
|
+
exports[`Low-level API > should fail join group request with new memberId 1`] = `
|
|
311
311
|
{
|
|
312
312
|
"_tag": undefined,
|
|
313
313
|
"_tag2": undefined,
|
|
@@ -323,7 +323,7 @@ exports[`Request handler > should fail join group request with new memberId 1`]
|
|
|
323
323
|
}
|
|
324
324
|
`;
|
|
325
325
|
|
|
326
|
-
exports[`
|
|
326
|
+
exports[`Low-level API > should fetch messages 1`] = `
|
|
327
327
|
{
|
|
328
328
|
"_tag": undefined,
|
|
329
329
|
"_tag2": undefined,
|
|
@@ -339,7 +339,7 @@ exports[`Request handler > should fetch messages 1`] = `
|
|
|
339
339
|
"highWatermark": 1n,
|
|
340
340
|
"lastStableOffset": 1n,
|
|
341
341
|
"logStartOffset": 0n,
|
|
342
|
-
"partitionIndex":
|
|
342
|
+
"partitionIndex": 6,
|
|
343
343
|
"preferredReadReplica": -1,
|
|
344
344
|
"records": [
|
|
345
345
|
{
|
|
@@ -433,7 +433,7 @@ exports[`Request handler > should fetch messages 1`] = `
|
|
|
433
433
|
}
|
|
434
434
|
`;
|
|
435
435
|
|
|
436
|
-
exports[`
|
|
436
|
+
exports[`Low-level API > should fetch offsets 1`] = `
|
|
437
437
|
{
|
|
438
438
|
"_tag": undefined,
|
|
439
439
|
"_tag2": undefined,
|
|
@@ -464,7 +464,7 @@ exports[`Request handler > should fetch offsets 1`] = `
|
|
|
464
464
|
}
|
|
465
465
|
`;
|
|
466
466
|
|
|
467
|
-
exports[`
|
|
467
|
+
exports[`Low-level API > should find coordinator 1`] = `
|
|
468
468
|
{
|
|
469
469
|
"_tag": undefined,
|
|
470
470
|
"_tag2": undefined,
|
|
@@ -483,7 +483,7 @@ exports[`Request handler > should find coordinator 1`] = `
|
|
|
483
483
|
}
|
|
484
484
|
`;
|
|
485
485
|
|
|
486
|
-
exports[`
|
|
486
|
+
exports[`Low-level API > should heartbeat 1`] = `
|
|
487
487
|
{
|
|
488
488
|
"_tag": undefined,
|
|
489
489
|
"_tag2": undefined,
|
|
@@ -492,7 +492,7 @@ exports[`Request handler > should heartbeat 1`] = `
|
|
|
492
492
|
}
|
|
493
493
|
`;
|
|
494
494
|
|
|
495
|
-
exports[`
|
|
495
|
+
exports[`Low-level API > should init producer id 1`] = `
|
|
496
496
|
{
|
|
497
497
|
"_tag": undefined,
|
|
498
498
|
"_tag2": undefined,
|
|
@@ -503,7 +503,7 @@ exports[`Request handler > should init producer id 1`] = `
|
|
|
503
503
|
}
|
|
504
504
|
`;
|
|
505
505
|
|
|
506
|
-
exports[`
|
|
506
|
+
exports[`Low-level API > should join group 1`] = `
|
|
507
507
|
{
|
|
508
508
|
"_tag": undefined,
|
|
509
509
|
"_tag2": undefined,
|
|
@@ -561,7 +561,7 @@ exports[`Request handler > should join group 1`] = `
|
|
|
561
561
|
}
|
|
562
562
|
`;
|
|
563
563
|
|
|
564
|
-
exports[`
|
|
564
|
+
exports[`Low-level API > should leave group 1`] = `
|
|
565
565
|
{
|
|
566
566
|
"_tag": undefined,
|
|
567
567
|
"_tag2": undefined,
|
|
@@ -578,7 +578,7 @@ exports[`Request handler > should leave group 1`] = `
|
|
|
578
578
|
}
|
|
579
579
|
`;
|
|
580
580
|
|
|
581
|
-
exports[`
|
|
581
|
+
exports[`Low-level API > should produce messages 1`] = `
|
|
582
582
|
{
|
|
583
583
|
"_tag": undefined,
|
|
584
584
|
"_tag2": undefined,
|
|
@@ -592,7 +592,7 @@ exports[`Request handler > should produce messages 1`] = `
|
|
|
592
592
|
"baseOffset": 0n,
|
|
593
593
|
"errorCode": 0,
|
|
594
594
|
"errorMessage": null,
|
|
595
|
-
"index":
|
|
595
|
+
"index": 6,
|
|
596
596
|
"logAppendTime": -1n,
|
|
597
597
|
"logStartOffset": 0n,
|
|
598
598
|
"recordErrors": [],
|
|
@@ -604,7 +604,7 @@ exports[`Request handler > should produce messages 1`] = `
|
|
|
604
604
|
}
|
|
605
605
|
`;
|
|
606
606
|
|
|
607
|
-
exports[`
|
|
607
|
+
exports[`Low-level API > should request api versions 1`] = `
|
|
608
608
|
{
|
|
609
609
|
"errorCode": 0,
|
|
610
610
|
"throttleTimeMs": 0,
|
|
@@ -898,7 +898,7 @@ exports[`Request handler > should request api versions 1`] = `
|
|
|
898
898
|
}
|
|
899
899
|
`;
|
|
900
900
|
|
|
901
|
-
exports[`
|
|
901
|
+
exports[`Low-level API > should request metadata for a topic 1`] = `
|
|
902
902
|
{
|
|
903
903
|
"_tag": undefined,
|
|
904
904
|
"_tag2": undefined,
|
|
@@ -925,7 +925,7 @@ exports[`Request handler > should request metadata for a topic 1`] = `
|
|
|
925
925
|
"rack": null,
|
|
926
926
|
},
|
|
927
927
|
],
|
|
928
|
-
"clusterId": "4L6g3nShT-eMCtK--X86sw",
|
|
928
|
+
"clusterId": "Some(4L6g3nShT-eMCtK--X86sw)",
|
|
929
929
|
"controllerId": 0,
|
|
930
930
|
"throttleTimeMs": 0,
|
|
931
931
|
"topics": [
|
|
@@ -944,7 +944,7 @@ exports[`Request handler > should request metadata for a topic 1`] = `
|
|
|
944
944
|
"leaderEpoch": 0,
|
|
945
945
|
"leaderId": 0,
|
|
946
946
|
"offlineReplicas": [],
|
|
947
|
-
"partitionIndex":
|
|
947
|
+
"partitionIndex": 6,
|
|
948
948
|
"replicaNodes": [
|
|
949
949
|
0,
|
|
950
950
|
],
|
|
@@ -958,7 +958,7 @@ exports[`Request handler > should request metadata for a topic 1`] = `
|
|
|
958
958
|
"leaderEpoch": 0,
|
|
959
959
|
"leaderId": 0,
|
|
960
960
|
"offlineReplicas": [],
|
|
961
|
-
"partitionIndex":
|
|
961
|
+
"partitionIndex": 0,
|
|
962
962
|
"replicaNodes": [
|
|
963
963
|
0,
|
|
964
964
|
],
|
|
@@ -972,7 +972,7 @@ exports[`Request handler > should request metadata for a topic 1`] = `
|
|
|
972
972
|
"leaderEpoch": 0,
|
|
973
973
|
"leaderId": 0,
|
|
974
974
|
"offlineReplicas": [],
|
|
975
|
-
"partitionIndex":
|
|
975
|
+
"partitionIndex": 2,
|
|
976
976
|
"replicaNodes": [
|
|
977
977
|
0,
|
|
978
978
|
],
|
|
@@ -986,7 +986,7 @@ exports[`Request handler > should request metadata for a topic 1`] = `
|
|
|
986
986
|
"leaderEpoch": 0,
|
|
987
987
|
"leaderId": 0,
|
|
988
988
|
"offlineReplicas": [],
|
|
989
|
-
"partitionIndex":
|
|
989
|
+
"partitionIndex": 1,
|
|
990
990
|
"replicaNodes": [
|
|
991
991
|
0,
|
|
992
992
|
],
|
|
@@ -1000,7 +1000,7 @@ exports[`Request handler > should request metadata for a topic 1`] = `
|
|
|
1000
1000
|
"leaderEpoch": 0,
|
|
1001
1001
|
"leaderId": 0,
|
|
1002
1002
|
"offlineReplicas": [],
|
|
1003
|
-
"partitionIndex":
|
|
1003
|
+
"partitionIndex": 9,
|
|
1004
1004
|
"replicaNodes": [
|
|
1005
1005
|
0,
|
|
1006
1006
|
],
|
|
@@ -1014,7 +1014,7 @@ exports[`Request handler > should request metadata for a topic 1`] = `
|
|
|
1014
1014
|
"leaderEpoch": 0,
|
|
1015
1015
|
"leaderId": 0,
|
|
1016
1016
|
"offlineReplicas": [],
|
|
1017
|
-
"partitionIndex":
|
|
1017
|
+
"partitionIndex": 8,
|
|
1018
1018
|
"replicaNodes": [
|
|
1019
1019
|
0,
|
|
1020
1020
|
],
|
|
@@ -1028,7 +1028,7 @@ exports[`Request handler > should request metadata for a topic 1`] = `
|
|
|
1028
1028
|
"leaderEpoch": 0,
|
|
1029
1029
|
"leaderId": 0,
|
|
1030
1030
|
"offlineReplicas": [],
|
|
1031
|
-
"partitionIndex":
|
|
1031
|
+
"partitionIndex": 5,
|
|
1032
1032
|
"replicaNodes": [
|
|
1033
1033
|
0,
|
|
1034
1034
|
],
|
|
@@ -1056,7 +1056,7 @@ exports[`Request handler > should request metadata for a topic 1`] = `
|
|
|
1056
1056
|
"leaderEpoch": 0,
|
|
1057
1057
|
"leaderId": 0,
|
|
1058
1058
|
"offlineReplicas": [],
|
|
1059
|
-
"partitionIndex":
|
|
1059
|
+
"partitionIndex": 3,
|
|
1060
1060
|
"replicaNodes": [
|
|
1061
1061
|
0,
|
|
1062
1062
|
],
|
|
@@ -1070,7 +1070,7 @@ exports[`Request handler > should request metadata for a topic 1`] = `
|
|
|
1070
1070
|
"leaderEpoch": 0,
|
|
1071
1071
|
"leaderId": 0,
|
|
1072
1072
|
"offlineReplicas": [],
|
|
1073
|
-
"partitionIndex":
|
|
1073
|
+
"partitionIndex": 7,
|
|
1074
1074
|
"replicaNodes": [
|
|
1075
1075
|
0,
|
|
1076
1076
|
],
|
|
@@ -1083,7 +1083,7 @@ exports[`Request handler > should request metadata for a topic 1`] = `
|
|
|
1083
1083
|
}
|
|
1084
1084
|
`;
|
|
1085
1085
|
|
|
1086
|
-
exports[`
|
|
1086
|
+
exports[`Low-level API > should request metadata for all topics 1`] = `
|
|
1087
1087
|
{
|
|
1088
1088
|
"_tag": undefined,
|
|
1089
1089
|
"_tag2": undefined,
|
|
@@ -1110,7 +1110,7 @@ exports[`Request handler > should request metadata for all topics 1`] = `
|
|
|
1110
1110
|
"rack": null,
|
|
1111
1111
|
},
|
|
1112
1112
|
],
|
|
1113
|
-
"clusterId": "4L6g3nShT-eMCtK--X86sw",
|
|
1113
|
+
"clusterId": "Some(4L6g3nShT-eMCtK--X86sw)",
|
|
1114
1114
|
"controllerId": 0,
|
|
1115
1115
|
"throttleTimeMs": 0,
|
|
1116
1116
|
"topics": [
|
|
@@ -1118,22 +1118,8 @@ exports[`Request handler > should request metadata for all topics 1`] = `
|
|
|
1118
1118
|
"_tag": undefined,
|
|
1119
1119
|
"errorCode": 0,
|
|
1120
1120
|
"isInternal": false,
|
|
1121
|
-
"name": "
|
|
1121
|
+
"name": "kafka-ts-test-topic",
|
|
1122
1122
|
"partitions": [
|
|
1123
|
-
{
|
|
1124
|
-
"_tag": undefined,
|
|
1125
|
-
"errorCode": 0,
|
|
1126
|
-
"isrNodes": [
|
|
1127
|
-
0,
|
|
1128
|
-
],
|
|
1129
|
-
"leaderEpoch": 0,
|
|
1130
|
-
"leaderId": 0,
|
|
1131
|
-
"offlineReplicas": [],
|
|
1132
|
-
"partitionIndex": 9,
|
|
1133
|
-
"replicaNodes": [
|
|
1134
|
-
0,
|
|
1135
|
-
],
|
|
1136
|
-
},
|
|
1137
1123
|
{
|
|
1138
1124
|
"_tag": undefined,
|
|
1139
1125
|
"errorCode": 0,
|
|
@@ -1148,128 +1134,6 @@ exports[`Request handler > should request metadata for all topics 1`] = `
|
|
|
1148
1134
|
0,
|
|
1149
1135
|
],
|
|
1150
1136
|
},
|
|
1151
|
-
{
|
|
1152
|
-
"_tag": undefined,
|
|
1153
|
-
"errorCode": 0,
|
|
1154
|
-
"isrNodes": [
|
|
1155
|
-
0,
|
|
1156
|
-
],
|
|
1157
|
-
"leaderEpoch": 0,
|
|
1158
|
-
"leaderId": 0,
|
|
1159
|
-
"offlineReplicas": [],
|
|
1160
|
-
"partitionIndex": 1,
|
|
1161
|
-
"replicaNodes": [
|
|
1162
|
-
0,
|
|
1163
|
-
],
|
|
1164
|
-
},
|
|
1165
|
-
{
|
|
1166
|
-
"_tag": undefined,
|
|
1167
|
-
"errorCode": 0,
|
|
1168
|
-
"isrNodes": [
|
|
1169
|
-
0,
|
|
1170
|
-
],
|
|
1171
|
-
"leaderEpoch": 0,
|
|
1172
|
-
"leaderId": 0,
|
|
1173
|
-
"offlineReplicas": [],
|
|
1174
|
-
"partitionIndex": 2,
|
|
1175
|
-
"replicaNodes": [
|
|
1176
|
-
0,
|
|
1177
|
-
],
|
|
1178
|
-
},
|
|
1179
|
-
{
|
|
1180
|
-
"_tag": undefined,
|
|
1181
|
-
"errorCode": 0,
|
|
1182
|
-
"isrNodes": [
|
|
1183
|
-
0,
|
|
1184
|
-
],
|
|
1185
|
-
"leaderEpoch": 0,
|
|
1186
|
-
"leaderId": 0,
|
|
1187
|
-
"offlineReplicas": [],
|
|
1188
|
-
"partitionIndex": 5,
|
|
1189
|
-
"replicaNodes": [
|
|
1190
|
-
0,
|
|
1191
|
-
],
|
|
1192
|
-
},
|
|
1193
|
-
{
|
|
1194
|
-
"_tag": undefined,
|
|
1195
|
-
"errorCode": 0,
|
|
1196
|
-
"isrNodes": [
|
|
1197
|
-
0,
|
|
1198
|
-
],
|
|
1199
|
-
"leaderEpoch": 0,
|
|
1200
|
-
"leaderId": 0,
|
|
1201
|
-
"offlineReplicas": [],
|
|
1202
|
-
"partitionIndex": 3,
|
|
1203
|
-
"replicaNodes": [
|
|
1204
|
-
0,
|
|
1205
|
-
],
|
|
1206
|
-
},
|
|
1207
|
-
{
|
|
1208
|
-
"_tag": undefined,
|
|
1209
|
-
"errorCode": 0,
|
|
1210
|
-
"isrNodes": [
|
|
1211
|
-
0,
|
|
1212
|
-
],
|
|
1213
|
-
"leaderEpoch": 0,
|
|
1214
|
-
"leaderId": 0,
|
|
1215
|
-
"offlineReplicas": [],
|
|
1216
|
-
"partitionIndex": 8,
|
|
1217
|
-
"replicaNodes": [
|
|
1218
|
-
0,
|
|
1219
|
-
],
|
|
1220
|
-
},
|
|
1221
|
-
{
|
|
1222
|
-
"_tag": undefined,
|
|
1223
|
-
"errorCode": 0,
|
|
1224
|
-
"isrNodes": [
|
|
1225
|
-
0,
|
|
1226
|
-
],
|
|
1227
|
-
"leaderEpoch": 0,
|
|
1228
|
-
"leaderId": 0,
|
|
1229
|
-
"offlineReplicas": [],
|
|
1230
|
-
"partitionIndex": 0,
|
|
1231
|
-
"replicaNodes": [
|
|
1232
|
-
0,
|
|
1233
|
-
],
|
|
1234
|
-
},
|
|
1235
|
-
{
|
|
1236
|
-
"_tag": undefined,
|
|
1237
|
-
"errorCode": 0,
|
|
1238
|
-
"isrNodes": [
|
|
1239
|
-
0,
|
|
1240
|
-
],
|
|
1241
|
-
"leaderEpoch": 0,
|
|
1242
|
-
"leaderId": 0,
|
|
1243
|
-
"offlineReplicas": [],
|
|
1244
|
-
"partitionIndex": 4,
|
|
1245
|
-
"replicaNodes": [
|
|
1246
|
-
0,
|
|
1247
|
-
],
|
|
1248
|
-
},
|
|
1249
|
-
{
|
|
1250
|
-
"_tag": undefined,
|
|
1251
|
-
"errorCode": 0,
|
|
1252
|
-
"isrNodes": [
|
|
1253
|
-
0,
|
|
1254
|
-
],
|
|
1255
|
-
"leaderEpoch": 0,
|
|
1256
|
-
"leaderId": 0,
|
|
1257
|
-
"offlineReplicas": [],
|
|
1258
|
-
"partitionIndex": 7,
|
|
1259
|
-
"replicaNodes": [
|
|
1260
|
-
0,
|
|
1261
|
-
],
|
|
1262
|
-
},
|
|
1263
|
-
],
|
|
1264
|
-
"topicAuthorizedOperations": -2147483648,
|
|
1265
|
-
"topicId": "Any<UUID>",
|
|
1266
|
-
},
|
|
1267
|
-
{
|
|
1268
|
-
"_tag": undefined,
|
|
1269
|
-
"errorCode": 0,
|
|
1270
|
-
"isInternal": false,
|
|
1271
|
-
"name": "kafka-ts-test-topic",
|
|
1272
|
-
"partitions": [
|
|
1273
1137
|
{
|
|
1274
1138
|
"_tag": undefined,
|
|
1275
1139
|
"errorCode": 0,
|
|
@@ -1293,7 +1157,7 @@ exports[`Request handler > should request metadata for all topics 1`] = `
|
|
|
1293
1157
|
"leaderEpoch": 0,
|
|
1294
1158
|
"leaderId": 0,
|
|
1295
1159
|
"offlineReplicas": [],
|
|
1296
|
-
"partitionIndex":
|
|
1160
|
+
"partitionIndex": 2,
|
|
1297
1161
|
"replicaNodes": [
|
|
1298
1162
|
0,
|
|
1299
1163
|
],
|
|
@@ -1321,7 +1185,7 @@ exports[`Request handler > should request metadata for all topics 1`] = `
|
|
|
1321
1185
|
"leaderEpoch": 0,
|
|
1322
1186
|
"leaderId": 0,
|
|
1323
1187
|
"offlineReplicas": [],
|
|
1324
|
-
"partitionIndex":
|
|
1188
|
+
"partitionIndex": 9,
|
|
1325
1189
|
"replicaNodes": [
|
|
1326
1190
|
0,
|
|
1327
1191
|
],
|
|
@@ -1335,7 +1199,7 @@ exports[`Request handler > should request metadata for all topics 1`] = `
|
|
|
1335
1199
|
"leaderEpoch": 0,
|
|
1336
1200
|
"leaderId": 0,
|
|
1337
1201
|
"offlineReplicas": [],
|
|
1338
|
-
"partitionIndex":
|
|
1202
|
+
"partitionIndex": 8,
|
|
1339
1203
|
"replicaNodes": [
|
|
1340
1204
|
0,
|
|
1341
1205
|
],
|
|
@@ -1354,20 +1218,6 @@ exports[`Request handler > should request metadata for all topics 1`] = `
|
|
|
1354
1218
|
0,
|
|
1355
1219
|
],
|
|
1356
1220
|
},
|
|
1357
|
-
{
|
|
1358
|
-
"_tag": undefined,
|
|
1359
|
-
"errorCode": 0,
|
|
1360
|
-
"isrNodes": [
|
|
1361
|
-
0,
|
|
1362
|
-
],
|
|
1363
|
-
"leaderEpoch": 0,
|
|
1364
|
-
"leaderId": 0,
|
|
1365
|
-
"offlineReplicas": [],
|
|
1366
|
-
"partitionIndex": 7,
|
|
1367
|
-
"replicaNodes": [
|
|
1368
|
-
0,
|
|
1369
|
-
],
|
|
1370
|
-
},
|
|
1371
1221
|
{
|
|
1372
1222
|
"_tag": undefined,
|
|
1373
1223
|
"errorCode": 0,
|
|
@@ -1391,7 +1241,7 @@ exports[`Request handler > should request metadata for all topics 1`] = `
|
|
|
1391
1241
|
"leaderEpoch": 0,
|
|
1392
1242
|
"leaderId": 0,
|
|
1393
1243
|
"offlineReplicas": [],
|
|
1394
|
-
"partitionIndex":
|
|
1244
|
+
"partitionIndex": 3,
|
|
1395
1245
|
"replicaNodes": [
|
|
1396
1246
|
0,
|
|
1397
1247
|
],
|
|
@@ -1405,7 +1255,7 @@ exports[`Request handler > should request metadata for all topics 1`] = `
|
|
|
1405
1255
|
"leaderEpoch": 0,
|
|
1406
1256
|
"leaderId": 0,
|
|
1407
1257
|
"offlineReplicas": [],
|
|
1408
|
-
"partitionIndex":
|
|
1258
|
+
"partitionIndex": 7,
|
|
1409
1259
|
"replicaNodes": [
|
|
1410
1260
|
0,
|
|
1411
1261
|
],
|
|
@@ -1418,7 +1268,7 @@ exports[`Request handler > should request metadata for all topics 1`] = `
|
|
|
1418
1268
|
}
|
|
1419
1269
|
`;
|
|
1420
1270
|
|
|
1421
|
-
exports[`
|
|
1271
|
+
exports[`Low-level API > should sync group 1`] = `
|
|
1422
1272
|
{
|
|
1423
1273
|
"_tag": undefined,
|
|
1424
1274
|
"_tag2": undefined,
|
package/src/api/fetch.ts
CHANGED
|
@@ -8,6 +8,8 @@ export const enum IsolationLevel {
|
|
|
8
8
|
READ_COMMITTED = 1,
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
export type FetchResponse = Awaited<ReturnType<(typeof FETCH)['response']>>;
|
|
12
|
+
|
|
11
13
|
export const FETCH = createApi({
|
|
12
14
|
apiKey: 1,
|
|
13
15
|
apiVersion: 16,
|
|
@@ -138,9 +140,12 @@ const decodeRecordBatch = (decoder: Decoder) => {
|
|
|
138
140
|
const recordBatchDecoder = new Decoder(decoder.read(size));
|
|
139
141
|
|
|
140
142
|
const results = [];
|
|
141
|
-
while (recordBatchDecoder.getBufferLength() > recordBatchDecoder.getOffset()) {
|
|
143
|
+
while (recordBatchDecoder.getBufferLength() > recordBatchDecoder.getOffset() + 12) {
|
|
142
144
|
const baseOffset = recordBatchDecoder.readInt64();
|
|
143
145
|
const batchLength = recordBatchDecoder.readInt32();
|
|
146
|
+
if (!batchLength) {
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
144
149
|
|
|
145
150
|
const batchDecoder = new Decoder(recordBatchDecoder.read(batchLength));
|
|
146
151
|
|
package/src/api/index.ts
CHANGED
|
@@ -37,7 +37,9 @@ export const API = {
|
|
|
37
37
|
SYNC_GROUP,
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
const apiNameByKey = Object.fromEntries(Object.entries(API).map(([k, v]) => [v.apiKey, k]));
|
|
41
|
+
|
|
42
|
+
export const getApiName = <Request, Response>(api: Api<Request, Response>) => apiNameByKey[api.apiKey];
|
|
41
43
|
|
|
42
44
|
export const API_ERROR = {
|
|
43
45
|
UNKNOWN_SERVER_ERROR: -1,
|
package/src/api/metadata.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createApi } from '../utils/api';
|
|
2
2
|
import { KafkaTSApiError } from '../utils/error';
|
|
3
3
|
|
|
4
|
-
export type Metadata = ReturnType<(typeof METADATA)['response']
|
|
4
|
+
export type Metadata = Awaited<ReturnType<(typeof METADATA)['response']>>;
|
|
5
5
|
|
|
6
6
|
export const METADATA = createApi({
|
|
7
7
|
apiKey: 3,
|
package/src/api/produce.ts
CHANGED
|
@@ -65,10 +65,9 @@ export const PRODUCE = createApi({
|
|
|
65
65
|
.writeVarIntBuffer(record.value)
|
|
66
66
|
.writeVarIntArray(record.headers, (encoder, header) =>
|
|
67
67
|
encoder.writeVarIntBuffer(header.key).writeVarIntBuffer(header.value),
|
|
68
|
-
)
|
|
69
|
-
.value();
|
|
68
|
+
);
|
|
70
69
|
|
|
71
|
-
return encoder.writeVarInt(recordBody.
|
|
70
|
+
return encoder.writeVarInt(recordBody.getByteLength()).writeEncoder(recordBody);
|
|
72
71
|
})
|
|
73
72
|
.value();
|
|
74
73
|
|
|
@@ -76,19 +75,17 @@ export const PRODUCE = createApi({
|
|
|
76
75
|
.writeInt32(partition.partitionLeaderEpoch)
|
|
77
76
|
.writeInt8(2) // magic byte
|
|
78
77
|
.writeUInt32(unsigned(crc32C(batchBody)))
|
|
79
|
-
.write(batchBody)
|
|
80
|
-
.value();
|
|
78
|
+
.write(batchBody);
|
|
81
79
|
|
|
82
80
|
const batch = new Encoder()
|
|
83
81
|
.writeInt64(partition.baseOffset)
|
|
84
|
-
.writeInt32(batchHeader.
|
|
85
|
-
.
|
|
86
|
-
.value();
|
|
82
|
+
.writeInt32(batchHeader.getByteLength())
|
|
83
|
+
.writeEncoder(batchHeader);
|
|
87
84
|
|
|
88
85
|
return encoder
|
|
89
86
|
.writeInt32(partition.index)
|
|
90
|
-
.writeUVarInt(batch.
|
|
91
|
-
.
|
|
87
|
+
.writeUVarInt(batch.getByteLength() + 1) // batch size
|
|
88
|
+
.writeEncoder(batch)
|
|
92
89
|
.writeUVarInt(0);
|
|
93
90
|
})
|
|
94
91
|
.writeUVarInt(0),
|
package/src/cluster.test.ts
CHANGED
|
@@ -8,14 +8,14 @@ import { createKafkaClient } from './client';
|
|
|
8
8
|
import { Cluster } from './cluster';
|
|
9
9
|
import { KafkaTSApiError } from './utils/error';
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
const kafka = createKafkaClient({
|
|
12
12
|
clientId: 'kafka-ts',
|
|
13
13
|
bootstrapServers: [{ host: 'localhost', port: 9092 }],
|
|
14
14
|
sasl: saslPlain({ username: 'admin', password: 'admin' }),
|
|
15
15
|
ssl: { ca: readFileSync('./certs/ca.crt').toString() },
|
|
16
16
|
});
|
|
17
17
|
|
|
18
|
-
describe.sequential('
|
|
18
|
+
describe.sequential('Low-level API', () => {
|
|
19
19
|
const groupId = randomBytes(16).toString('hex');
|
|
20
20
|
|
|
21
21
|
let cluster: Cluster;
|
package/src/cluster.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TcpSocketConnectOpts } from 'net';
|
|
2
2
|
import { TLSSocketOptions } from 'tls';
|
|
3
3
|
import { API } from './api';
|
|
4
|
+
import { Metadata } from './api/metadata';
|
|
4
5
|
import { Broker, SASLProvider } from './broker';
|
|
5
6
|
import { SendRequest } from './connection';
|
|
6
7
|
import { KafkaTSError } from './utils/error';
|
|
@@ -15,14 +16,14 @@ type ClusterOptions = {
|
|
|
15
16
|
|
|
16
17
|
export class Cluster {
|
|
17
18
|
private seedBroker = new Broker({ clientId: null, sasl: null, ssl: null, options: { port: 9092 } });
|
|
18
|
-
private
|
|
19
|
-
private brokerMetadata: Record<number,
|
|
20
|
-
{};
|
|
19
|
+
private brokerById: Record<number, Broker> = {};
|
|
20
|
+
private brokerMetadata: Record<number, Metadata['brokers'][number]> = {};
|
|
21
21
|
|
|
22
22
|
constructor(private options: ClusterOptions) {}
|
|
23
23
|
|
|
24
24
|
public async connect() {
|
|
25
25
|
this.seedBroker = await this.findSeedBroker();
|
|
26
|
+
this.brokerById = {};
|
|
26
27
|
|
|
27
28
|
const metadata = await this.sendRequest(API.METADATA, {
|
|
28
29
|
allowTopicAutoCreation: false,
|
|
@@ -33,11 +34,11 @@ export class Cluster {
|
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
public async disconnect() {
|
|
36
|
-
await Promise.all(this.
|
|
37
|
+
await Promise.all([this.seedBroker.disconnect(), ...Object.values(this.brokerById).map((x) => x.disconnect())]);
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
public setSeedBroker = async (nodeId: number) => {
|
|
40
|
-
await this.
|
|
41
|
+
await this.seedBroker.disconnect();
|
|
41
42
|
this.seedBroker = await this.acquireBroker(nodeId);
|
|
42
43
|
};
|
|
43
44
|
|
|
@@ -46,11 +47,10 @@ export class Cluster {
|
|
|
46
47
|
public sendRequestToNode =
|
|
47
48
|
(nodeId: number): SendRequest =>
|
|
48
49
|
async (...args) => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
broker = await this.acquireBroker(nodeId);
|
|
50
|
+
if (!this.brokerById[nodeId]) {
|
|
51
|
+
this.brokerById[nodeId] = await this.acquireBroker(nodeId);
|
|
52
52
|
}
|
|
53
|
-
return
|
|
53
|
+
return this.brokerById[nodeId].sendRequest(...args);
|
|
54
54
|
};
|
|
55
55
|
|
|
56
56
|
public async acquireBroker(nodeId: number) {
|
|
@@ -60,16 +60,10 @@ export class Cluster {
|
|
|
60
60
|
ssl: this.options.ssl,
|
|
61
61
|
options: this.brokerMetadata[nodeId],
|
|
62
62
|
});
|
|
63
|
-
this.brokers.push({ nodeId, broker });
|
|
64
63
|
await broker.connect();
|
|
65
64
|
return broker;
|
|
66
65
|
}
|
|
67
66
|
|
|
68
|
-
public async releaseBroker(broker: Broker) {
|
|
69
|
-
await broker.disconnect();
|
|
70
|
-
this.brokers = this.brokers.filter((x) => x.broker !== broker);
|
|
71
|
-
};
|
|
72
|
-
|
|
73
67
|
private async findSeedBroker() {
|
|
74
68
|
const randomizedBrokers = this.options.bootstrapServers.toSorted(() => Math.random() - 0.5);
|
|
75
69
|
for (const options of randomizedBrokers) {
|
|
@@ -81,7 +75,6 @@ export class Cluster {
|
|
|
81
75
|
options,
|
|
82
76
|
});
|
|
83
77
|
await broker.connect();
|
|
84
|
-
this.brokers.push({ nodeId: -1, broker });
|
|
85
78
|
return broker;
|
|
86
79
|
} catch (error) {
|
|
87
80
|
log.warn(`Failed to connect to seed broker ${options.host}:${options.port}`, error);
|