Expand description
Apache Kafka broker for the RustStream messaging
framework, backed by rdkafka / librdkafka.
§Transport model
A subscription is one consumer joining one consumer group on one topic; KafkaTopic
describes it, and the bare-string #[subscriber("orders")] form consumes the topic named
orders through KafkaBroker::default_group. On the publish side
OutgoingMessage::name is the destination topic, and a
PARTITION_KEY_HEADER header becomes the record’s native key, so Kafka itself keeps
per-key ordering.
Settlement follows Kafka’s committed-position model instead of per-message frames; the
Commit mode picks how:
Commit::Auto(the default): librdkafka auto-commit;ackand bothnackforms are advisory no-ops (the position is stored when a message is handed to the application, sonack(true)does not cause a redelivery).Commit::Tracked: precise at-least-once.acksettles its delivery and the stored position advances across everything settled below it, staying correct under concurrent handler lanes and across offset gaps (transaction markers, compacted topics).nack(false)settles the offset (drop);nack(true)leaves it unsettled, so Kafka redelivers from the committed position on the next fetch of the partition.
Configuration delegates to librdkafka: unset options mean librdkafka defaults, and the raw
config(key, value) passthroughs on the broker, the producer, and the descriptor reach
every property this crate does not surface as a typed option.
§The lifecycle ladder
Each state of the connection is its own type, so out-of-order use does not compile:
KafkaBroker::new(servers) configuration only, synchronous, no I/O
.connect() -> ConnectedKafkaBroker the live connection: subscriptions and publishers
.shutdown() -> ClosedKafkaBroker the terminal witness, carrying the flush resultKafkaBroker::new being synchronous is what lets a service compose with the synchronous
#[ruststream::app] builder; the runtime calls connect once at startup.
Publishers follow the same split: KafkaPublish (and its transactional and per-partition
transitions) is pure policy, constructible anywhere, with no publish surface at all; pairing
it with the connected broker produces the live KafkaPublisher. Handles paired before a
shutdown keep aliasing the closed connection, so their operations report
KafkaError::Closed rather than succeeding against a dead connection.
One publisher stands outside that split, on purpose: KafkaRetryPublisher, minted from
the unconnected broker for builder-time wiring that takes a live publisher rather than a
policy - retry_via, the deferred republish behind retry_after that Kafka needs because
it has no native delayed redelivery. See its documentation.
Modules§
- context
- Per-delivery context fields exposed to handlers.
- testing
- In-process test broker, behind the
testingfeature.
Structs§
- Closed
Kafka Broker - The terminal witness returned by
ConnectedBroker::shutdown. - Connected
Kafka Broker - The connected form of
KafkaBroker: the typed witness thatBroker::connectsucceeded. - EosPipeline
- An exactly-once pipeline over one transactional producer, the live form of
KafkaEosPublish. - EosReplies
- The
PublishTransformrelayingEOS_SOURCE_HEADERfrom the originating delivery onto the reply, so the pipeline’sPublisherimpl can pair the reply with its consumed offset. - Kafka
Broker - An Apache Kafka broker backed by
rdkafka/ librdkafka. - Kafka
EosPublish - The publish policy of
EosPipeline: the pipeline id (the producer’s transactional id) plus the commit interval, declared anywhere and paired with the connected broker at startup. - Kafka
Message - One Kafka delivery: an owned snapshot of the record plus its settlement handle.
- Kafka
Partitioned Publish - The publish policy of
TransactionalPartitions, reached fromKafkaTransactionalPublish::per_partition. - Kafka
Publish - The publish policy of
KafkaPublisher: pure declaration, no connection, no publish surface. - Kafka
Publisher - A live producer handle on the broker’s shared producer.
- Kafka
Retry Publisher - A publisher minted from an unconnected
KafkaBroker, for the one wiring that cannot take a policy. - Kafka
Seeker - Repositions a live
KafkaSubscriber, minted bySeekable::seeker. - Kafka
Subscriber - A consumer-group member on one topic, yielding
KafkaMessagedeliveries. - Kafka
Topic - A subscription to one Kafka topic through one consumer group.
- Kafka
Transactional Publish - The publish policy of
KafkaTransactionalPublisher: the transactional mode as its own type, reached fromKafkaPublish::transactional_id. - Kafka
Transactional Publisher - A live publisher that produces inside Kafka transactions.
- Round
Robin - A
PublishTransformdistributing replies round-robin across the firstcountpartitions. - Source
Offset - The source coordinates of one delivery, as
EosPipeline::publishneeds them. - Transactional
Partitions - Transactional publishers, one per source partition, materialized on first use.
Enums§
- Assignment
- The partition assignment strategy for the consumer group (librdkafka’s
partition.assignment.strategy). - Commit
- How processed deliveries are committed back to the consumer group.
- Kafka
Error - Errors returned by
KafkaBrokerand the types it hands out. - Kafka
Position - Where a subscription should resume reading.
- LaneKey
- What drives keyed worker lanes (
workers(n, by_key)) for this subscription. - Retry
- What
nack(true)does on this subscription (seeKafkaTopic::retry). - Start
Offset - Where a consumer group starts reading when it has no valid committed offset.
Constants§
- DLQ_
SOURCE_ OFFSET_ HEADER - See
DLQ_SOURCE_TOPIC_HEADER. - DLQ_
SOURCE_ PARTITION_ HEADER - See
DLQ_SOURCE_TOPIC_HEADER. - DLQ_
SOURCE_ TOPIC_ HEADER - Headers stamped onto a dead-lettered message with the origin of the failed delivery.
- EOS_
SOURCE_ HEADER - Header carrying a transactional delivery’s source coordinates through the reply path.
- PARTITION_
HEADER - Header naming the explicit destination partition for a publish (an ASCII decimal).
- PARTITION_
KEY_ HEADER - Header carrying a message’s partition key, mapped onto Kafka’s native record key.
- RETRY_
COUNT_ HEADER - Header carrying the number of retry republishes a message has been through.