From baa7ef37e9ca58834e414f3316d3db7fdf66f372 Mon Sep 17 00:00:00 2001 From: Luis Moreno Date: Tue, 7 Mar 2023 13:53:56 -0400 Subject: [PATCH] try to fix node example --- embeds/client-examples/node/example.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/embeds/client-examples/node/example.ts b/embeds/client-examples/node/example.ts index 7c46a4058..129dfb194 100644 --- a/embeds/client-examples/node/example.ts +++ b/embeds/client-examples/node/example.ts @@ -33,6 +33,9 @@ const produce = async () => { console.log("Connecting client to fluvio"); await fluvio.connect(); + await delay(500); + console.log("producing record"); + // Create a topic producer; const producer = await fluvio.topicProducer(TOPIC_NAME); await producer.send("example-key", "Hello World! - Time is " + Date()); @@ -43,11 +46,13 @@ const consume = async () => { // Connect to the fluvio cluster referenced in the cli profile. await fluvio.connect(); + await delay(1000); + // Create partition consumer const consumer = await fluvio.partitionConsumer(TOPIC_NAME, PARTITION); - console.log("read from the end"); - await consumer.stream(Offset.FromEnd(), async (record: Record) => { + console.log("read from beginning"); + await consumer.stream(Offset.FromBeginning(), async (record: Record) => { // handle record; console.log(`Key=${record.keyString()}, Value=${record.valueString()}`); process.exit(0); @@ -57,9 +62,16 @@ const consume = async () => { } }; +function delay(ms: number) { + return new Promise(resolve => setTimeout(resolve, ms)); +} + + // Create Fluvio Client Instance const fluvio = new Fluvio(); createTopic(); + + produce(); consume();