Skip to main content

Crate rustfs_kafka_async

Crate rustfs_kafka_async 

Source
Expand description

Async Kafka client built on top of the tokio runtime.

This crate provides native asynchronous Kafka clients built on tokio. It exposes three primary types:

  • AsyncKafkaClient: bootstrap and connection management for async code.
  • AsyncProducer: an async producer using non-blocking Kafka protocol I/O.
  • AsyncProducerBuilder: async builder for configuring and creating an AsyncProducer without blocking the tokio scheduler.
  • AsyncConsumer: an async consumer using non-blocking Kafka protocol I/O.
  • AsyncConsumerBuilder: async builder for configuring and creating an AsyncConsumer without blocking the tokio scheduler.

§Example

use rustfs_kafka_async::{AsyncKafkaClient, AsyncProducer};
use rustfs_kafka::producer::Record;

#[tokio::main]
async fn main() -> rustfs_kafka::error::Result<()> {
    // Create an async client from bootstrap hosts
    let client = AsyncKafkaClient::new(vec!["localhost:9092".to_owned()]).await?;
    // Create an async producer which manages a background task
    let mut producer = AsyncProducer::new(client).await?;

    // Send a single message and close the producer
    producer.send(&Record::from_value("test-topic", &b"hello"[..])).await?;
    producer.close().await?;
    Ok(())
}

Modules§

error
Error types and error handling utilities.

Structs§

AsyncConsumer
An async Kafka consumer.
AsyncConsumerBuilder
Builder for constructing an AsyncConsumer asynchronously.
AsyncKafkaClient
An async Kafka client for bootstrap and connection management.
AsyncProducer
An async Kafka producer.
AsyncProducerBuilder
Builder for constructing an AsyncProducer with non-blocking setup.
AsyncProducerConfig
Configuration for constructing an AsyncProducer.
Headers
A collection of key-value headers attached to a Kafka record.
Record
A structure representing a message to be sent to Kafka through the Producer API. Such a message is basically a key/value pair specifying the target topic and optionally the topic’s partition.
SaslConfig
SASL configuration options for KafkaClient.
SecurityConfig
Security relevant configuration options for KafkaClient.

Enums§

RequiredAcks
Possible choices on acknowledgement requirements when producing/sending messages to Kafka. See KafkaClient::produce_messages.

Traits§

AsBytes
A trait used by Producer to obtain the bytes Record::key and Record::value represent. This leaves the choice of the types for key and value with the client.