@orbit-stream/redpanda 1.0.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/LICENSE +21 -0
- package/README.md +70 -0
- package/index.d.ts +40 -0
- package/package.json +24 -0
- package/src/adapters/RedpandaAdapter.js +67 -0
- package/src/consumer/Consumer.js +91 -0
- package/src/producer/Producer.js +69 -0
- package/src/utils/createKafka.js +23 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 santhoshk382
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# orbit-stream-redpanda
|
|
2
|
+
|
|
3
|
+
High-performance Redpanda transport adapter for Orbit Stream.
|
|
4
|
+
|
|
5
|
+
# @orbit-stream/redpanda
|
|
6
|
+
|
|
7
|
+
High-performance Redpanda transport adapter for Orbit Stream.
|
|
8
|
+
|
|
9
|
+
Optimized for:
|
|
10
|
+
|
|
11
|
+
- high-throughput telemetry
|
|
12
|
+
- binary payloads
|
|
13
|
+
- batching
|
|
14
|
+
- low-latency streaming
|
|
15
|
+
- backpressure-aware processing
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
# Installation
|
|
20
|
+
|
|
21
|
+
```bash id="ygt1m4"
|
|
22
|
+
npm install @orbit-stream/redpanda
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
# Usage
|
|
28
|
+
|
|
29
|
+
```js id="w9d4p7"
|
|
30
|
+
const { RedpandaAdapter } = require("@orbit-stream/redpanda");
|
|
31
|
+
|
|
32
|
+
const stream = new RedpandaAdapter({
|
|
33
|
+
brokers: ["localhost:9092"],
|
|
34
|
+
|
|
35
|
+
groupId: "telemetry-group",
|
|
36
|
+
|
|
37
|
+
batchSize: 5000,
|
|
38
|
+
|
|
39
|
+
flushInterval: 100,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
await stream.connect();
|
|
43
|
+
|
|
44
|
+
await stream.publish("telemetry", {
|
|
45
|
+
value: Buffer.from("hello"),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
await stream.subscribe("telemetry", async (messages) => {
|
|
49
|
+
console.log(messages.length);
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
# Features
|
|
56
|
+
|
|
57
|
+
- KafkaJS based
|
|
58
|
+
- Redpanda optimized
|
|
59
|
+
- Batch publishing
|
|
60
|
+
- Batch consumption
|
|
61
|
+
- Buffer-first architecture
|
|
62
|
+
- Backpressure-aware
|
|
63
|
+
- High throughput optimized
|
|
64
|
+
- Binary payload support
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
# License
|
|
69
|
+
|
|
70
|
+
MIT
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { BaseAdapter, Message } from "@orbit-stream/core";
|
|
2
|
+
|
|
3
|
+
export interface RedpandaConfig {
|
|
4
|
+
clientId?: string;
|
|
5
|
+
|
|
6
|
+
brokers?: string[];
|
|
7
|
+
|
|
8
|
+
ssl?: boolean;
|
|
9
|
+
|
|
10
|
+
sasl?: any;
|
|
11
|
+
|
|
12
|
+
groupId?: string;
|
|
13
|
+
|
|
14
|
+
batchSize?: number;
|
|
15
|
+
|
|
16
|
+
flushInterval?: number;
|
|
17
|
+
|
|
18
|
+
maxInFlightRequests?: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class RedpandaAdapter extends BaseAdapter {
|
|
22
|
+
constructor(config?: RedpandaConfig);
|
|
23
|
+
|
|
24
|
+
connect(): Promise<void>;
|
|
25
|
+
|
|
26
|
+
disconnect(): Promise<void>;
|
|
27
|
+
|
|
28
|
+
publish(topic: string, message: Message): Promise<void>;
|
|
29
|
+
|
|
30
|
+
publishBatch(topic: string, messages: Message[]): Promise<void>;
|
|
31
|
+
|
|
32
|
+
subscribe(
|
|
33
|
+
topic: string,
|
|
34
|
+
handler: (messages: Message[]) => Promise<void> | void,
|
|
35
|
+
options?: {
|
|
36
|
+
fromBeginning?: boolean;
|
|
37
|
+
partitionsConsumedConcurrently?: number;
|
|
38
|
+
},
|
|
39
|
+
): Promise<void>;
|
|
40
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@orbit-stream/redpanda",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "High-performance Redpanda transport adapter for Orbit Stream.",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"src",
|
|
9
|
+
"index.d.ts"
|
|
10
|
+
],
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@orbit-stream/core": "^1.0.0",
|
|
13
|
+
"kafkajs": "^2.2.4"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"redpanda",
|
|
17
|
+
"kafka",
|
|
18
|
+
"stream",
|
|
19
|
+
"streaming",
|
|
20
|
+
"telemetry",
|
|
21
|
+
"orbit-stream"
|
|
22
|
+
],
|
|
23
|
+
"license": "MIT"
|
|
24
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const { BaseAdapter, BatchProcessor } = require("@orbit-stream/core");
|
|
2
|
+
|
|
3
|
+
const createKafka = require("../utils/createKafka");
|
|
4
|
+
|
|
5
|
+
const Producer = require("../producer/Producer");
|
|
6
|
+
|
|
7
|
+
const Consumer = require("../consumer/Consumer");
|
|
8
|
+
|
|
9
|
+
class RedpandaAdapter extends BaseAdapter {
|
|
10
|
+
constructor(config = {}) {
|
|
11
|
+
super(config);
|
|
12
|
+
|
|
13
|
+
this.kafka = createKafka(config);
|
|
14
|
+
|
|
15
|
+
this.producer = new Producer(this.kafka, config);
|
|
16
|
+
|
|
17
|
+
this.consumer = new Consumer(this.kafka, config);
|
|
18
|
+
|
|
19
|
+
this.batchProcessor = new BatchProcessor({
|
|
20
|
+
batchSize: config.batchSize || 5000,
|
|
21
|
+
|
|
22
|
+
flushInterval: config.flushInterval || 100,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async connect() {
|
|
27
|
+
await Promise.all([this.producer.connect(), this.consumer.connect()]);
|
|
28
|
+
|
|
29
|
+
this.emitConnected();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async disconnect() {
|
|
33
|
+
await Promise.all([this.producer.disconnect(), this.consumer.disconnect()]);
|
|
34
|
+
|
|
35
|
+
this.emitDisconnected();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async publish(topic, message) {
|
|
39
|
+
this.batchProcessor.add(
|
|
40
|
+
message,
|
|
41
|
+
|
|
42
|
+
async (batch) => {
|
|
43
|
+
await this.publishBatch(topic, batch);
|
|
44
|
+
},
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async publishBatch(topic, messages) {
|
|
49
|
+
return this.producer.publishBatch(
|
|
50
|
+
topic,
|
|
51
|
+
|
|
52
|
+
messages,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async subscribe(topic, handler, options = {}) {
|
|
57
|
+
return this.consumer.subscribe(
|
|
58
|
+
topic,
|
|
59
|
+
|
|
60
|
+
handler,
|
|
61
|
+
|
|
62
|
+
options,
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
module.exports = RedpandaAdapter;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
const { serializer, logger } = require("@orbit-stream/core");
|
|
2
|
+
|
|
3
|
+
class Consumer {
|
|
4
|
+
constructor(kafka, config = {}) {
|
|
5
|
+
this.consumer = kafka.consumer({
|
|
6
|
+
groupId: config.groupId || "orbit-stream-group",
|
|
7
|
+
|
|
8
|
+
sessionTimeout: 30000,
|
|
9
|
+
|
|
10
|
+
heartbeatInterval: 3000,
|
|
11
|
+
|
|
12
|
+
maxBytesPerPartition: 10485760,
|
|
13
|
+
|
|
14
|
+
minBytes: 1,
|
|
15
|
+
|
|
16
|
+
maxBytes: 52428800,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
this.connected = false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async connect() {
|
|
23
|
+
if (this.connected) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
await this.consumer.connect();
|
|
28
|
+
|
|
29
|
+
this.connected = true;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async disconnect() {
|
|
33
|
+
if (!this.connected) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
await this.consumer.disconnect();
|
|
38
|
+
|
|
39
|
+
this.connected = false;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async subscribe(topic, handler, options = {}) {
|
|
43
|
+
await this.consumer.subscribe({
|
|
44
|
+
topic,
|
|
45
|
+
|
|
46
|
+
fromBeginning: options.fromBeginning || false,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
await this.consumer.run({
|
|
50
|
+
autoCommit: true,
|
|
51
|
+
|
|
52
|
+
partitionsConsumedConcurrently:
|
|
53
|
+
options.partitionsConsumedConcurrently || 3,
|
|
54
|
+
|
|
55
|
+
eachBatchAutoResolve: true,
|
|
56
|
+
|
|
57
|
+
eachBatch: async ({
|
|
58
|
+
batch,
|
|
59
|
+
resolveOffset,
|
|
60
|
+
heartbeat,
|
|
61
|
+
commitOffsetsIfNecessary,
|
|
62
|
+
}) => {
|
|
63
|
+
const messages = new Array(batch.messages.length);
|
|
64
|
+
|
|
65
|
+
for (let i = 0; i < batch.messages.length; i++) {
|
|
66
|
+
const msg = batch.messages[i];
|
|
67
|
+
|
|
68
|
+
messages[i] = {
|
|
69
|
+
key: msg.key,
|
|
70
|
+
|
|
71
|
+
value: serializer.deserialize(msg.value),
|
|
72
|
+
|
|
73
|
+
headers: msg.headers,
|
|
74
|
+
|
|
75
|
+
timestamp: Number(msg.timestamp),
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
resolveOffset(msg.offset);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
await handler(messages);
|
|
82
|
+
|
|
83
|
+
await heartbeat();
|
|
84
|
+
|
|
85
|
+
await commitOffsetsIfNecessary();
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
module.exports = Consumer;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const { serializer, logger } = require("@orbit-stream/core");
|
|
2
|
+
|
|
3
|
+
class Producer {
|
|
4
|
+
constructor(kafka, config = {}) {
|
|
5
|
+
this.producer = kafka.producer({
|
|
6
|
+
allowAutoTopicCreation: true,
|
|
7
|
+
|
|
8
|
+
transactionTimeout: 30000,
|
|
9
|
+
|
|
10
|
+
maxInFlightRequests: config.maxInFlightRequests || 5,
|
|
11
|
+
|
|
12
|
+
idempotent: true,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
this.connected = false;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async connect() {
|
|
19
|
+
if (this.connected) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
await this.producer.connect();
|
|
24
|
+
|
|
25
|
+
this.connected = true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async disconnect() {
|
|
29
|
+
if (!this.connected) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
await this.producer.disconnect();
|
|
34
|
+
|
|
35
|
+
this.connected = false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async publishBatch(topic, messages) {
|
|
39
|
+
const kafkaMessages = new Array(messages.length);
|
|
40
|
+
|
|
41
|
+
for (let i = 0; i < messages.length; i++) {
|
|
42
|
+
const msg = messages[i];
|
|
43
|
+
|
|
44
|
+
kafkaMessages[i] = {
|
|
45
|
+
key: msg.key,
|
|
46
|
+
|
|
47
|
+
value: serializer.serialize(msg.value),
|
|
48
|
+
|
|
49
|
+
headers: msg.headers,
|
|
50
|
+
|
|
51
|
+
timestamp: msg.timestamp ? String(msg.timestamp) : undefined,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
await this.producer.send({
|
|
56
|
+
topic,
|
|
57
|
+
|
|
58
|
+
compression: 1,
|
|
59
|
+
|
|
60
|
+
acks: -1,
|
|
61
|
+
|
|
62
|
+
timeout: 30000,
|
|
63
|
+
|
|
64
|
+
messages: kafkaMessages,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
module.exports = Producer;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const { Kafka } = require("kafkajs");
|
|
2
|
+
|
|
3
|
+
function createKafka(config = {}) {
|
|
4
|
+
return new Kafka({
|
|
5
|
+
clientId: config.clientId || "orbit-stream",
|
|
6
|
+
|
|
7
|
+
brokers: config.brokers || ["localhost:9092"],
|
|
8
|
+
|
|
9
|
+
ssl: config.ssl || false,
|
|
10
|
+
|
|
11
|
+
sasl: config.sasl,
|
|
12
|
+
|
|
13
|
+
retry: {
|
|
14
|
+
retries: 10,
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
connectionTimeout: 30000,
|
|
18
|
+
|
|
19
|
+
requestTimeout: 30000,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = createKafka;
|