Skip to main content

TransactionalPartitions

Struct TransactionalPartitions 

Source
pub struct TransactionalPartitions { /* private fields */ }
Expand description

Lazily materialized transactional publishers, one per source partition.

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 instance in the application state serves every handler invocation.

§Examples

use ruststream_rdkafka::{KafkaBroker, TransactionalPartitions};

let broker = KafkaBroker::new(["localhost:9092"]);
let publishers = TransactionalPartitions::new(broker.publisher(), "billing-svc-1");
// In a handler: the delivery's source partition picks the publisher.
let publisher = publishers.for_partition(3); // transactional id "billing-svc-1-p3"

Implementations§

Source§

impl TransactionalPartitions

Source

pub fn new(template: KafkaPublisher, id_base: impl Into<String>) -> Self

Creates the per-partition publisher set over template (which carries the broker connection and any queue_timeout); each partition’s publisher gets the transactional id "{id_base}-p{partition}". A transactional id already set on the template is ignored.

id_base must be stable across restarts and unique per service instance - it is what scopes zombie fencing.

Source

pub fn transaction_timeout(self, timeout: Duration) -> Self

The control-call deadline (KafkaPublisher::transaction_timeout) applied to each partition’s publisher. Configure before handing the set out: publishers already materialized keep their deadline.

Source

pub fn for_partition(&self, partition: i32) -> KafkaPublisher

The publisher owning partition’s transactional id, created 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.

§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

Source§

fn clone(&self) -> TransactionalPartitions

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TransactionalPartitions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more