🦀 Krafka
A pure Rust, async-native Apache Kafka client designed for high performance, safety, and ease of use.
✨ Features
- 🦀 Pure Rust: No librdkafka or C dependencies
- ⚡ Async-native: Built on Tokio for true async I/O
- 🔒 Zero unsafe: Safe Rust by default
- 🚀 High performance: Zero-copy buffers, inline hot paths, efficient batching
- 📦 Full protocol support: Kafka protocol with all compression codecs
- 🔐 TLS/SSL encryption: Using rustls for secure connections
- 🔑 SASL authentication: PLAIN, SCRAM-SHA-256/512 mechanisms
- 💯 Transactions: Exactly-once semantics with transactional producer
- ☁️ Cloud-native: First-class AWS MSK support including IAM auth
🚀 Quick Start
Add Krafka to your Cargo.toml:
[]
= "0.1"
= { = "1", = ["full"] }
# For AWS MSK IAM authentication with full SDK support:
# krafka = { version = "0.1", features = ["aws-msk"] }
Producer
use Producer;
use Result;
async
Consumer
use ;
use Result;
use Duration;
async
Admin Client
use ;
use Result;
use Duration;
async
Transactional Producer
For exactly-once semantics across multiple partitions:
use TransactionalProducer;
use Result;
async
📦 Modules
| Module | Description |
|---|---|
producer |
High-throughput message production with batching and compression |
consumer |
Consumer groups with rebalancing and offset management |
admin |
Cluster administration (create/delete topics, describe cluster) |
protocol |
Kafka wire protocol implementation |
auth |
Authentication (SASL/PLAIN, SASL/SCRAM, AWS MSK IAM) |
🗜️ Compression
Krafka supports all Kafka compression codecs:
use Producer;
use Compression;
let producer = builder
.bootstrap_servers
.compression // Fast compression
.build
.await?;
| Codec | Crate | Characteristics |
|---|---|---|
Compression::Gzip |
flate2 | Best ratio, slower |
Compression::Snappy |
snap | Good balance |
Compression::Lz4 |
lz4_flex | Fastest |
Compression::Zstd |
zstd | Best modern choice |
⚡ Performance Tuning
High Throughput Producer
use ;
use Compression;
use Duration;
let producer = builder
.bootstrap_servers
.acks
.compression
.batch_size // 1MB batches
.linger // Allow batching
.build
.await?;
Low Latency Consumer
use Consumer;
use Duration;
let consumer = builder
.bootstrap_servers
.group_id
.fetch_min_bytes
.fetch_max_wait
.build
.await?;
📚 Documentation
Full documentation is available at hupe1980.github.io/krafka
- Getting Started
- Producer Guide
- Consumer Guide
- Admin Client
- Configuration Reference
- Performance Tuning
- Architecture Overview
- Metrics & Observability
- Error Handling
- Authentication
🎮 Examples
Run the examples with:
# Producer example
# Consumer example
# Advanced consumer example (pause/resume, seek, manual commits)
# Admin client example
# Transactional producer example
# Authentication examples (SASL, SCRAM, MSK IAM)
📊 Status
Krafka is feature-complete and production-ready.
Features:
- ✅ Protocol layer (all message types, compression, ACL messages, transactions)
- ✅ Network layer (async connections, pooling, TLS/SSL)
- ✅ Producer (batching with linger timer, partitioning, compression, retry policy, idempotence)
- ✅ Consumer (polling, offset management, seek, pause/resume, rebalance listeners, cooperative sticky assignor)
- ✅ Admin Client (topic CRUD, partitions, configuration, ACL management)
- ✅ Authentication (SASL/PLAIN, SASL/SCRAM-SHA-256/512, AWS MSK IAM with SDK support)
- ✅ TLS/SSL encryption (rustls, mTLS support)
- ✅ Transactions (exactly-once semantics with transactional producer)
- ✅ Metrics (counters, gauges, latency tracking)
- ✅ Tracing (OpenTelemetry-compatible spans)
🤝 Contributing
Contributions are welcome!
📄 License
Licensed under the MIT License.