Principle:Fede1024 Rust rdkafka Transactional Message Production
| Knowledge Sources | |
|---|---|
| Domains | Messaging, Transactions |
| Last Updated | 2026-02-07 19:00 GMT |
Overview
A synchronous message enqueue operation within a Kafka transaction boundary for exactly-once production.
Description
Transactional Message Production is the act of enqueuing messages within an active transaction. Unlike FutureProducer::send which provides an async delivery future, BaseProducer::send enqueues synchronously and never blocks. The message is buffered internally and will be delivered (or fail) as part of the transaction commit.
Within a transaction, all produced messages are invisible to consumers until commit_transaction succeeds. If the transaction is aborted, all messages are discarded. The BaseRecord struct provides the message builder with topic, key, payload, partition, timestamp, headers, and a delivery opaque for callback tracking.
Usage
Use this principle when producing messages within a Kafka transaction. The BaseProducer::send is the appropriate method because transactions require synchronous enqueue control (not async). Messages become visible only after commit_transaction.
Theoretical Basis
Pseudo-code logic:
// Abstract algorithm
producer.begin_transaction()
for record in records {
producer.send(BaseRecord::to(topic).payload(data).key(key))
}
producer.commit_transaction(timeout)
// All messages now visible atomically