Rust

The rust client is the core client for all language clients. It has all the features before any of the other clients as well as having good support for the Admin API. This client uses async rust for all blocking calls.

 

Connect

To get a fluvio connection do:

let fluvio = Fluvio::connect().await.expect("Failed to connect to fluvio");
 

Produce

To create a producer do:

let producer = fluvio.topic_producer("my-fluvio-topic").await.expect("Failed to create a producer");
 

Send

Once you’ve got a producer, send to this topic via:

producer.send("my-key", "my-value").await.expect("Failed to send into a record");
 

Consume

To create a consumer do:

let consumer = fluvio.partition_consumer("my-topic", 0).await.expect("failed to create consumer");
 

Stream

To create a stream do:

let mut stream = consumer.stream(Offset::beginning()).await.expect("Failed to create stream");

To use the stream do:

use futures::StreamExt;
while let Some(Ok(record)) = stream.next().await {
    let key = record.key().map(|key| String::from_utf8_lossy(key).to_string());
    let value = String::from_utf8_lossy(record.value()).to_string();
    println!("Got event: key={:?}, value={}", key, value);
}

Refer to the fluvio docs.rs page for full detail.