Fluvio TypeScript / NodeJS Client

The NodeJS client for communicating with Fluvio clusters.


import Fluvio, { RecordSet } from '@fluvio/client';

// define the name of the topic to use
const TOPIC_NAME = "my-topic"

// define the partition where the topic
// records will be stored;
const PARTITION = 0

// Instantiate a new fluvio client
const fluvio = new Fluvio({
host: '127.0.0.1',
port: 9003
});

// Explicitly connect to the fluvio cluster;
await fluvio.connect();

//// Fluvio Admin Client

// Create a new Fluvio Admin Client to manage
// topics and partitions
const admin = await fluvio.admin();

// Create a new topic
await admin.createTopic(TOPIC_NAME)

//// Topic Producer

// Create a topic producer for the topic;
const producer = await fluvio.topicProducer(TOPIC_NAME);

// Send a new topic record
producer.sendRecord("stringified data", PARTITION)

//// Partition Consumer

// Instantiate a new topic listener;
const consumer = await fluvio.partitionConsumer(TOPIC_NAME, PARTITION)

// Listen for new topics sent by a topic producer;
await consumer.listen(async (data: RecordSet) => {
// handle data record
})

TypeScript wrapper around native fluvio core module written in Rust.

Core module is generated from node-bindgen. This TypeScript wrapper provides type definitions and generates the JavaScript client.

Implements

Constructors

  • Parameters

    • Optionaloptions: Options

      Options provides top-level access to common configurable values used by the Fluvio client.

    Returns default

Methods

  • Parameters

    • Optionaloptions: Partial<Options>

      Optionally pass in connection host options (e.g. { host: '' }) uses the partial Options type; This does not override the default options, only replaces default options in this case;

    Returns Promise<FluvioClient>

  • Creates a new PartitionConsumer for the given topic and partition

    Currently, consumers are scoped to both a specific Fluvio topic and to a particular partition within that topic. That means that if you have a topic with multiple partitions, then in order to receive all of the events in all of the partitions, you will need to create one consumer per partition.

    Parameters

    • topic: string

      topic string

    • partition: number

      partition id

    Returns Promise<PartitionConsumer>

  • Creates a new TopicProducer for the given topic name

    Currently, producers are scoped to a specific Fluvio topic. That means when you send events via a producer, you must specify which partition each event should go to.

    Parameters

    • topic: string

      Name of the topic to create a producer for

    Returns Promise<TopicProducer>

  • Add static method to quickly create a connected client;

    Parameters

    • Optionaloptions: Options

      Fluvio options passed into new fluvio instance;

    Returns Promise<default>