This is an automated email from the ASF dual-hosted git repository.

spetz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iggy-website.git


The following commit(s) were added to refs/heads/main by this push:
     new f78fd6ed fix(docs): make Node SDK quickstart and examples runnable 
(closes #51) (#52)
f78fd6ed is described below

commit f78fd6ed6a7e9f1222cc7576aae70dd10fe4b78e
Author: Justin Mclean <[email protected]>
AuthorDate: Wed Aug 5 17:47:08 2026 +1000

    fix(docs): make Node SDK quickstart and examples runnable (closes #51) (#52)
---
 content/docs/sdk/node/examples.mdx | 53 +++++++++++++++----------
 content/docs/sdk/node/intro.mdx    | 80 ++++++++++++++++++++++----------------
 2 files changed, 79 insertions(+), 54 deletions(-)

diff --git a/content/docs/sdk/node/examples.mdx 
b/content/docs/sdk/node/examples.mdx
index a4fce2cb..7e6e8bcd 100644
--- a/content/docs/sdk/node/examples.mdx
+++ b/content/docs/sdk/node/examples.mdx
@@ -18,20 +18,31 @@ Working examples are available in the 
[examples/node](https://github.com/apache/
 ```typescript
 import { Client, Partitioning } from 'apache-iggy';
 
+const STREAM_NAME = 'sample-stream';
+const TOPIC_NAME = 'sample-topic';
+
 const client = new Client({
   transport: 'TCP',
-  options: { port: 8090, host: '127.0.0.1', keepAlive: true },
+  options: { port: 8090, host: '127.0.0.1' },
   credentials: { username: 'iggy', password: 'iggy' },
 });
 
-const stream = await client.stream.create({ name: 'sample-stream' });
-const topic = await client.topic.create({
-  streamId: stream.id,
-  name: 'sample-topic',
-  partitionCount: 1,
-  compressionAlgorithm: 1,
-  replicationFactor: 1,
-});
+// Re-running this example is fine: only create what is missing.
+const streams = await client.stream.list();
+const stream =
+  streams.find((s) => s.name === STREAM_NAME) ??
+  (await client.stream.create({ name: STREAM_NAME }));
+
+const topics = await client.topic.list({ streamId: stream.id });
+const topic =
+  topics.find((t) => t.name === TOPIC_NAME) ??
+  (await client.topic.create({
+    streamId: stream.id,
+    name: TOPIC_NAME,
+    partitionCount: 1,
+    compressionAlgorithm: 1,
+    replicationFactor: 1,
+  }));
 
 const messages = Array.from({ length: 10 }, (_, i) => ({
   id: i + 1,
@@ -43,11 +54,11 @@ await client.message.send({
   streamId: stream.id,
   topicId: topic.id,
   messages,
-  partition: Partitioning.PartitionId(
-    topic.partitions[0].id
-  ),
+  partition: Partitioning.Balanced,
 });
 
+console.log(`Sent ${messages.length} message(s)`);
+
 await client.destroy();
 ```
 
@@ -56,8 +67,8 @@ await client.destroy();
 ```typescript
 import { Client, PollingStrategy, Consumer } from 'apache-iggy';
 
-const STREAM_ID = 1;
-const TOPIC_ID = 1;
+const STREAM_NAME = 'sample-stream';
+const TOPIC_NAME = 'sample-topic';
 const PARTITION_ID = 0;
 
 const client = new Client({
@@ -66,21 +77,21 @@ const client = new Client({
   credentials: { username: 'iggy', password: 'iggy' },
 });
 
+// Next with autocommit continues from this consumer's last committed offset,
+// so each run picks up where the previous one finished.
 const polledMessages = await client.message.poll({
-  streamId: STREAM_ID,
-  topicId: TOPIC_ID,
+  streamId: STREAM_NAME,
+  topicId: TOPIC_NAME,
   consumer: Consumer.Single,
   partitionId: PARTITION_ID,
-  pollingStrategy: PollingStrategy.Offset(BigInt(0)),
+  pollingStrategy: PollingStrategy.Next,
   count: 10,
-  autocommit: false,
+  autocommit: true,
 });
 
 for (const message of polledMessages.messages) {
   const payload = message.payload.toString('utf8');
-  console.log(
-    `Offset: ${message.headers.offset}, Payload: ${payload}`
-  );
+  console.log(`Offset: ${message.headers.offset}, Payload: ${payload}`);
 }
 
 await client.destroy();
diff --git a/content/docs/sdk/node/intro.mdx b/content/docs/sdk/node/intro.mdx
index 687771c9..e6a06301 100644
--- a/content/docs/sdk/node/intro.mdx
+++ b/content/docs/sdk/node/intro.mdx
@@ -17,30 +17,48 @@ npm install apache-iggy
 ```typescript
 import { Client, Partitioning } from 'apache-iggy';
 
+const STREAM_NAME = 'sample-stream';
+const TOPIC_NAME = 'sample-topic';
+
 const client = new Client({
   transport: 'TCP',
-  options: {
-    port: 8090,
-    host: '127.0.0.1',
-  },
-  credentials: {
-    username: 'iggy',
-    password: 'iggy',
-  },
+  options: { port: 8090, host: '127.0.0.1' },
+  credentials: { username: 'iggy', password: 'iggy' },
 });
 
-const messages = Array.from({ length: 10 }).map((_, i) => ({
+// Re-running this example is fine: only create what is missing.
+const streams = await client.stream.list();
+const stream =
+  streams.find((s) => s.name === STREAM_NAME) ??
+  (await client.stream.create({ name: STREAM_NAME }));
+
+const topics = await client.topic.list({ streamId: stream.id });
+const topic =
+  topics.find((t) => t.name === TOPIC_NAME) ??
+  (await client.topic.create({
+    streamId: stream.id,
+    name: TOPIC_NAME,
+    partitionCount: 1,
+    compressionAlgorithm: 1,
+    replicationFactor: 1,
+  }));
+
+const messages = Array.from({ length: 10 }, (_, i) => ({
   id: i + 1,
   headers: [],
   payload: `message-${i + 1}`,
 }));
 
 await client.message.send({
-  streamId: 1,
-  topicId: 1,
+  streamId: stream.id,
+  topicId: topic.id,
   messages,
-  partition: Partitioning.PartitionId(1),
+  partition: Partitioning.Balanced,
 });
+
+console.log(`Sent ${messages.length} message(s)`);
+
+await client.destroy();
 ```
 
 ### Consumer
@@ -48,38 +66,34 @@ await client.message.send({
 ```typescript
 import { Client, PollingStrategy, Consumer } from 'apache-iggy';
 
+const STREAM_NAME = 'sample-stream';
+const TOPIC_NAME = 'sample-topic';
+const PARTITION_ID = 0;
+
 const client = new Client({
   transport: 'TCP',
-  options: {
-    port: 8090,
-    host: '127.0.0.1',
-  },
-  credentials: {
-    username: 'iggy',
-    password: 'iggy',
-  },
+  options: { port: 8090, host: '127.0.0.1' },
+  credentials: { username: 'iggy', password: 'iggy' },
 });
 
-const STREAM_ID = 1;
-const TOPIC_ID = 1;
-const PARTITION_ID = 1;
-
+// Next with autocommit continues from this consumer's last committed offset,
+// so each run picks up where the previous one finished.
 const polledMessages = await client.message.poll({
-  streamId: STREAM_ID,
-  topicId: TOPIC_ID,
+  streamId: STREAM_NAME,
+  topicId: TOPIC_NAME,
   consumer: Consumer.Single,
   partitionId: PARTITION_ID,
-  pollingStrategy: PollingStrategy.Offset(BigInt(0)),
+  pollingStrategy: PollingStrategy.Next,
   count: 10,
-  autocommit: false,
+  autocommit: true,
 });
 
-if (polledMessages && polledMessages.messages.length > 0) {
-  for (const message of polledMessages.messages) {
-    const payload = message.payload.toString('utf8');
-    console.log(`Offset: ${message.headers.offset}, Payload: ${payload}`);
-  }
+for (const message of polledMessages.messages) {
+  const payload = message.payload.toString('utf8');
+  console.log(`Offset: ${message.headers.offset}, Payload: ${payload}`);
 }
+
+await client.destroy();
 ```
 
 ## Examples

Reply via email to