ruststream-rdkafka connects a RustStream service to Apache Kafka over
rdkafka, the librdkafka binding. Handlers, routing, codecs and
middleware come from the framework; this crate is the transport.
Features
- Consumer groups as descriptors: one topic, a set of topics or a regex, or partitions assigned by hand.
- Three commit modes: librdkafka auto-commit, precise per-message acknowledgement, and commits inside a producer transaction.
- Record keys and placement: the partition key becomes the Kafka key, and a publish can pin a record to a partition.
- Native batches cut from what librdkafka has already fetched.
- Retry caps and dead-letter topics declared where the handler is mounted.
- Transactions and exactly-once pipelines as publish policies.
- Repositioning: a handler moves its subscription to an offset or a timestamp.
- Confluent Schema Registry framing, with Avro and Protobuf, behind features.
- AsyncAPI with the specification's
kafkabinding, behind theasyncapifeature. - Tests on the production app: the app
mainruns, withKafkaBrokerconnected to an in-process Kafka, or against a real cluster withTestApp::start_live.
Install
[]
= { = "0.7", = ["macros", "json"] }
= "0.7"
= { = "1", = ["derive"] }
[]
= { = "0.7", = ["testing"] }
The crate builds librdkafka from source, so a C toolchain is required. Optional features:
testing, asyncapi, schema-registry, avro, protobuf, msgpack, cbor, ssl,
ssl-vendored and zstd.
Write a service
use *;
use ;
// `Outgoing`, `PartialEq` and `Serialize` are here for the test below, which publishes an order
// and asserts on the decoded one.
async
#[ruststream::app] generates main, so the binary understands run and asyncapi gen.
Scaffold a fresh project from the template:
Test it
TestApp runs the app main runs, with KafkaBroker connected to an in-process Kafka and no
cluster.
use TestApp;
let tb = start.await?;
// `publish` returns once the handlers it woke have settled, so the assertions read finished state.
tb.
.message
.to
.publish
.await?;
tb.
.subscriber
.assert_called_once
.settled;
tb.
.
.assert_called_once
.with;
Documentation
- Getting started - installation and a first service against a local Kafka.
- Guides - consumer groups and ordering, commits, retries, replay, exactly-once, Schema Registry, Protobuf, testing and a production cluster.
- Components - one page per part of the crate: the broker, subscriptions, settlement, publishing, transactions, the registry formats and testing.
- Architecture - how the crate sits between librdkafka and the runtime.
- Benchmarks - what the crate costs over the raw client.
- API reference - every item on docs.rs.
- The framework: https://powersemmi.github.io/ruststream/latest/
Minimum supported Rust version
The MSRV is 1.95, edition 2024.
Contributing
See CONTRIBUTING.md.
License
Licensed under the Apache-2.0 license.