kafrust
A pure Rust Kafka client with no librdkafka or C toolchain dependency.
kafrust is the high-level client crate in the kafrust workspace. It provides
Tokio-based producer, direct consumer, and alpha classic consumer group APIs on
top of the companion kafrust-protocol
wire-format crate.
Current release: 0.2.1.
This crate is alpha. Use it for experiments, local broker checks, simple
internal tools, and API evaluation. For broad production Kafka workloads that
need mature features immediately, rust-rdkafka remains the practical Rust
default today.
Design Goals
- Keep Kafka concepts visible in public APIs.
- Stay pure Rust with no
librdkafka, C client binding, or required C toolchain. - Make protocol and runtime behavior auditable through small, tested slices.
- Claim compatibility only when a real broker profile has been verified.
The public model intentionally exposes Kafka terms such as bootstrap servers, client IDs, topics, partitions, offsets, acknowledgements, metadata refresh, consumer groups, generations, members, heartbeats, and commits.
Install
[]
= "0.2"
= { = "1", = ["macros", "rt"] }
For a multi-threaded application runtime, enable Tokio's rt-multi-thread
feature in the application.
Producer
use ;
async
Batch Producer
Producer::send_batch returns metadata in input order. Use
Producer::send_batch_report when partial per-record failures need to be
inspected without losing successful records.
use ;
async
Buffered Producer
ProducerConfig::build_buffered creates an opt-in buffered producer. Records are
flushed by linger time, record count, byte count, explicit flush, or close.
use ;
async
Direct Consumer
The direct consumer path fetches from explicit topic partitions and offsets. This is useful when consumer group behavior is not needed.
use ConsumerConfig;
async
Consumer Group
The consumer group API is an alpha classic consumer group path with join, sync, heartbeat, poll, and offset commit support.
use ConsumerGroupConfig;
async
Security Protocols
SecurityProtocol models Kafka connection modes:
PlaintextTlsSaslPlaintextSaslTls
Plaintext is the default and the only implemented transport in 0.2.1.
TLS and SASL variants are configuration targets and currently return
Error::Unsupported before connecting.
Compatibility
The 0.2.x alpha line is verified against a single-node Apache Kafka 3.7.2
KRaft broker over PLAINTEXT.
Verified high-level paths include:
ApiVersions v0andMetadata v1roundtrips.- Producer single-record, batch, and buffered sends.
- Direct topic-partition fetch using Fetch v2 response decoding.
- Classic consumer group join, sync, heartbeat, poll, and offset commit.
Current Limits
- APIs are pre-
1.0and can change between minor versions. - TLS and SASL are not implemented yet.
- Broker compatibility is verified against Kafka
3.7.2only. - Multi-broker clusters, leader failover, rack awareness, and partition expansion are not yet claimed.
- Idempotent producers, transactions, compression, admin APIs, and broad observability are not implemented yet.
acks=0remains unsupported because the current request loop expects a broker response.
Examples
Run examples from the repository with a local Kafka broker:
KAFRUST_BOOTSTRAP_SERVERS=localhost:9092 \
KAFRUST_TOPIC=kafrust-smoke \
Available examples include:
broker_roundtripproducer_sendproducer_send_batchproducer_bufferedconsumer_fetchfind_group_coordinatorconsumer_group_poll