fix: fix offset logging and readme
This commit is contained in:
parent
0d25d323d0
commit
692f2f7bac
@ -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).
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user