From 692f2f7bacc5250d7a7d23a105ca2dd3b8a1f6a6 Mon Sep 17 00:00:00 2001 From: magne Date: Mon, 19 Aug 2024 17:47:56 +0200 Subject: [PATCH] fix: fix offset logging and readme --- javascript-nodejs-stream/README.md | 15 +++++++++++++-- .../offset_tracking_receive.js | 5 ++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/javascript-nodejs-stream/README.md b/javascript-nodejs-stream/README.md index 433bb3e..dde542f 100644 --- a/javascript-nodejs-stream/README.md +++ b/javascript-nodejs-stream/README.md @@ -14,7 +14,18 @@ Apart from [Node.js](https://nodejs.org/en/download/), these examples use the [` Code examples are executed via `npm`: - npm run publish - npm run receive +[Tutorial one: "Hello World!"](https://www.rabbitmq.com/tutorials/tutorial-one-javascript-stream): + +```shell +npm run send +npm run receive +``` + +[Tutorial two: Offset Tracking](https://www.rabbitmq.com/tutorials/tutorial-two-javascript-stream): + +```shell +npm run offset-tracking-publish +npm run offset-tracking-receive +``` To learn more, see [`coders51/rabbitmq-stream-js-client`](https://github.com/coders51/rabbitmq-stream-js-client). diff --git a/javascript-nodejs-stream/offset_tracking_receive.js b/javascript-nodejs-stream/offset_tracking_receive.js index 0985418..b0726c6 100644 --- a/javascript-nodejs-stream/offset_tracking_receive.js +++ b/javascript-nodejs-stream/offset_tracking_receive.js @@ -19,8 +19,7 @@ async function main() { let offsetSpecification = rabbit.Offset.first(); try { const offset = await client.queryOffset({ reference: consumerRef, stream: streamName }); - firstOffset = offset + 1n; - offsetSpecification = rabbit.Offset.offset(firstOffset); + offsetSpecification = rabbit.Offset.offset(offset + 1n); } catch (e) {} let lastOffset = offsetSpecification.value; @@ -34,7 +33,6 @@ async function main() { console.log("First message received"); } if (messageCount % 10 === 0) { - console.log("Storing offset"); await consumer.storeOffset(message.offset); } if (message.content.toString() === "marker") { @@ -43,6 +41,7 @@ async function main() { await consumer.storeOffset(message.offset); console.log(`Done consuming, first offset was ${firstOffset}, last offset was ${lastOffset}`); await consumer.close(true); + process.exit(0); } } );