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 anAsyncProducerwithout blocking the tokio scheduler.AsyncConsumer: an async consumer using non-blocking Kafka protocol I/O.AsyncConsumerBuilder: async builder for configuring and creating anAsyncConsumerwithout 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§
- Async
Consumer - An async Kafka consumer.
- Async
Consumer Builder - Builder for constructing an
AsyncConsumerasynchronously. - Async
Kafka Client - An async Kafka client for bootstrap and connection management.
- Async
Producer - An async Kafka producer.
- Async
Producer Builder - Builder for constructing an
AsyncProducerwith non-blocking setup. - Async
Producer Config - 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
ProducerAPI. Such a message is basically a key/value pair specifying the target topic and optionally the topic’s partition. - Sasl
Config - SASL configuration options for
KafkaClient. - Security
Config - Security relevant configuration options for
KafkaClient.
Enums§
- Required
Acks - Possible choices on acknowledgement requirements when
producing/sending messages to Kafka. See
KafkaClient::produce_messages.
Traits§
- AsBytes
- A trait used by
Producerto obtain the bytesRecord::keyandRecord::valuerepresent. This leaves the choice of the types forkeyandvaluewith the client.