Skip to content

Commit 2dd25d8

Browse files
committed
Add quickstart
1 parent b7fd389 commit 2dd25d8

File tree

2 files changed

+65
-3
lines changed

2 files changed

+65
-3
lines changed

QUICKSTART.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Basic Producer Example
2+
3+
```javascript
4+
const { Kafka } = require('../..').KafkaJS
5+
6+
async function producerStart() {
7+
const producer = new Kafka().producer({
8+
'bootstrap.servers': '<fill>',
9+
});
10+
11+
await producer.connect();
12+
13+
const deliveryReports = await producer.send({
14+
topic: 'topic2',
15+
messages: [
16+
{ value: 'v222', partition: 0 },
17+
{ value: 'v11', partition: 0, key: 'x' },
18+
]
19+
});
20+
21+
await producer.disconnect();
22+
}
23+
24+
producerStart();
25+
```
26+
27+
# Basic Consumer Example
28+
29+
```javascript
30+
const { Kafka } = require('../..').KafkaJS
31+
32+
async function consumerStart() {
33+
const consumer = new Kafka().consumer({
34+
'bootstrap.servers': '<fill>',
35+
'group.id': 'test',
36+
'auto.offset.reset': 'earliest',
37+
});
38+
39+
await consumer.connect();
40+
41+
await consumer.subscribe({ topics: [ "topic" ] });
42+
43+
consumer.run({
44+
eachMessage: async ({ topic, partition, message }) => {
45+
console.log({
46+
topic,
47+
partition,
48+
offset: message.offset,
49+
key: message.key?.toString(),
50+
value: message.value.toString(),
51+
});
52+
},
53+
});
54+
55+
// When done consuming
56+
// await consumer.disconnect();
57+
}
58+
59+
consumerStart();
60+
```
61+
62+
See the examples in the [examples](examples) directory for more in-depth examples.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ __This library currently uses `librdkafka` based off of the master branch.__
3636
The following configurations are supported for this early access preview:
3737

3838
* Any supported version of Node.js (The two LTS versions, 18 and 20, and the latest version, 21).
39-
* Linux (x64 and arm64) - only glibc, not musl/alpine.
40-
* macOS - arm64/m1 only
39+
* Linux (x64 and arm64) - both glibc and musl/alpine.
40+
* macOS - arm64/m1.
4141

4242
Installation on any of these platforms is meant to be seamless, without any C/C++ compilation required. It can be installed
4343
from GitHub:
@@ -48,7 +48,7 @@ $ npm install "git+ssh://git@github.com/confluentinc/confluent-kafka-js.git#v0.1
4848

4949
# Getting Started
5050

51-
1. If you're starting afresh, you can use the [quickstart guide](QUICKSTART.md) (TBA).
51+
1. If you're starting afresh, you can use the [quickstart guide](QUICKSTART.md).
5252
2. If you're migrating from `kafkajs`, you can use the [migration guide](MIGRATION.md#kafkajs).
5353
2. If you're migrating from `node-rdkafka`, you can use the [migration guide](MIGRATION.md#node-rdkafka).
5454

0 commit comments

Comments
 (0)