Expand description
Kafka Rust Client
A pure Rust Kafka client library based on Tokio async runtime. Supports SASL authentication (PLAIN, SCRAM-SHA-256, SCRAM-SHA-512, GSSAPI/Kerberos) and TLS encryption.
§Quick Start
ⓘ
use kafka_client::Client;
// Create client — connects to cluster, discovers all brokers
let client = Client::builder(vec!["localhost:9092".into()])
.with_plaintext()
.build()
.await?;
// Producer — send messages
let producer = client.producer_default().await;
producer.send(ProducerRecord::new("my-topic", b"hello".into())).await?;
// Consumer — read messages
let mut consumer = client.consumer_default();
consumer.subscribe(vec!["my-topic".into()]).await?;
let records = consumer.poll().await?;
client.close().await?;§Advanced Configuration
ⓘ
// Custom producer config
let producer = client.producer(
ProducerConfig::new().with_acks(-1).with_retries(3)
).await;
// Consumer with group coordination
let mut consumer = client.consumer(
ConsumerConfig::new("my-group").with_earliest()
);Re-exports§
pub use transport::SecurityProtocol;pub use transport::TlsConfig;pub use kafka_client_protocol as protocol;
Modules§
- admin
- Admin client — cluster management and inspection.
- connection
- Connection layer — TCP/TLS connection management with Kafka protocol
- transport
Structs§
- Client
- Unified Kafka client.
- Client
Builder - Builder for constructing a
Client. - Client
Config - Declarative configuration for creating a
Client. - Consumer
- Consumer
Config - Kafka consumer configuration.
- Consumer
Record - Consumer
Stream - A streaming wrapper that yields individual
ConsumerRecordvalues. - Group
Handle - Header
- Message header
- Kafka
Error Code - Kafka 协议错误码,对应 Kafka 协议规范中定义的错误码。
- Kerberos
Credentials - Kerberos credentials model (distinct from SASL username/password).
- Metadata
Cache - Metadata cache with TTL-based expiry and O(1) partition leader lookup.
- Offset
Handle - Partition
Router - Partition router (cloneable for concurrent access)
- Producer
- High-level Kafka Producer.
- Producer
Config - Producer
Record - Producer record
- Record
Metadata - Send metadata
- Sasl
Credentials - SASL credentials.
Enums§
- Auto
Offset Reset - Kafka
Error - Kerberos
Error - Errors returned by Kerberos / GSS-API operations.
- Partition
Assignment Strategy - Partition
Routing - Partition routing strategy
- Sasl
Mechanism Type - SASL mechanism type.
Constants§
Traits§
- GssContext
- Kerberos GSS-API (krb5 mechanism) authentication context.
Functions§
- builder
- Convenience builder function — equivalent to
Client::builder(...).