rustfs_kafka_async/lib.rs
1//! Async Kafka client built on top of the tokio runtime.
2//!
3//! This crate provides native asynchronous Kafka clients built on tokio.
4//! It exposes three primary types:
5//!
6//! - [`AsyncKafkaClient`]: bootstrap and connection management for async code.
7//! - [`AsyncProducer`]: an async producer using non-blocking Kafka protocol I/O.
8//! - [`AsyncProducerBuilder`]: async builder for configuring and creating an
9//! `AsyncProducer` without blocking the tokio scheduler.
10//! - [`AsyncConsumer`]: an async consumer using non-blocking Kafka protocol I/O.
11//! - [`AsyncConsumerBuilder`]: async builder for configuring and creating an
12//! `AsyncConsumer` without blocking the tokio scheduler.
13//!
14//! # Example
15//!
16//! ```no_run
17//! use rustfs_kafka_async::{AsyncKafkaClient, AsyncProducer};
18//! use rustfs_kafka::producer::Record;
19//!
20//! #[tokio::main]
21//! async fn main() -> rustfs_kafka::error::Result<()> {
22//! // Create an async client from bootstrap hosts
23//! let client = AsyncKafkaClient::new(vec!["localhost:9092".to_owned()]).await?;
24//! // Create an async producer which manages a background task
25//! let mut producer = AsyncProducer::new(client).await?;
26//!
27//! // Send a single message and close the producer
28//! producer.send(&Record::from_value("test-topic", &b"hello"[..])).await?;
29//! producer.close().await?;
30//! Ok(())
31//! }
32//! ```
33
34mod client;
35mod connection;
36mod consumer;
37mod metrics;
38mod producer;
39
40pub use client::AsyncKafkaClient;
41pub use consumer::{AsyncConsumer, AsyncConsumerBuilder};
42pub use producer::{AsyncProducer, AsyncProducerBuilder, AsyncProducerConfig};
43
44// Re-export core types from the sync crate for convenience
45pub use rustfs_kafka::client::{RequiredAcks, SaslConfig, SecurityConfig};
46pub use rustfs_kafka::error;
47pub use rustfs_kafka::producer::{AsBytes, Headers, Record};