pub struct TransactionalPartitions { /* private fields */ }Expand description
Transactional publishers, one per source partition, materialized on first use.
Kafka permits one open transaction per producer and one live producer per transactional id
(initializing a second fences the first), so concurrent transactional handlers need one
producer each. The source partition is the natural scope: under the default
LaneKey::Partition worker pool a partition’s deliveries
process serially on one lane, so a publisher per partition gives every lane an independent
transaction with no coordination. The id set ("{base}-p{partition}") follows the topic’s
partitions rather than the worker count: changing workers(n) neither changes the ids nor
weakens zombie fencing - the scheme Kafka Streams uses for its per-task producers.
Not for LaneKey::RecordKey pools: record-key lanes spread
one partition across lanes, so two lanes would share a partition’s publisher and collide
on its single transaction (KafkaError::TransactionBusy).
Clones share the cache, so one injected handle serves every handler invocation.
Implementations§
Source§impl TransactionalPartitions
impl TransactionalPartitions
Sourcepub async fn for_partition(
&self,
partition: i32,
) -> Result<KafkaTransactionalPublisher, KafkaError>
pub async fn for_partition( &self, partition: i32, ) -> Result<KafkaTransactionalPublisher, KafkaError>
The publisher owning partition’s transactional id, created and initialized on first
use.
partition is the delivery’s source partition (KafkaContext’s Partition field in a
handler); passing anything else still works but forfeits the serialization argument
that makes the per-partition scope safe.
§Errors
Returns KafkaError::Closed once the broker has shut down and
KafkaError::Publish when the partition’s producer cannot be created or its
transactions cannot be initialized.
§Panics
Panics when the internal cache mutex is poisoned, which requires a prior panic while materializing a publisher (an invariant violation, not an operational failure).
Trait Implementations§
Source§impl Clone for TransactionalPartitions
impl Clone for TransactionalPartitions
Source§fn clone(&self) -> TransactionalPartitions
fn clone(&self) -> TransactionalPartitions
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more