Skip to content

Commit

Permalink
try to fix node example
Browse files Browse the repository at this point in the history
  • Loading branch information
morenol committed Mar 7, 2023
1 parent bc3db67 commit baa7ef3
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions embeds/client-examples/node/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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);
Expand All @@ -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();

0 comments on commit baa7ef3

Please sign in to comment.