Skip to main content

TransactionalPublisher

Trait TransactionalPublisher 

Source
pub trait TransactionalPublisher: Publisher {
    // Required methods
    fn begin_transaction(
        &self,
    ) -> impl Future<Output = Result<(), Self::Error>> + Send;
    fn commit(&self) -> impl Future<Output = Result<(), Self::Error>> + Send;
    fn abort(&self) -> impl Future<Output = Result<(), Self::Error>> + Send;
}
Expand description

A publisher that supports broker-side transactions.

Implementations must guarantee that messages published between begin_transaction and commit either all become visible to subscribers or none of them do.

Misuse is an error, never a silent no-op: a commit or abort with no open transaction, and a begin_transaction while one is open, must return Self::Error. A caller can therefore trust that Ok from commit means “an open transaction committed”, not “there was nothing to commit”. The conformance transactional suite checks these paths.

This is the borrowed kind of the two transaction capabilities: the handle carries at most one broker-side transaction, and begin_transaction takes an exclusive claim on it. Kafka-like brokers, whose client object holds exactly one transaction per producer, implement only this kind. Brokers whose transactions are client buffers can additionally implement OwnedTransactions, the owned kind: every call there opens an independent buffer-owning Transaction value, so concurrent transactions on one handle are legal.

Required Methods§

Source

fn begin_transaction( &self, ) -> impl Future<Output = Result<(), Self::Error>> + Send

Begins a new transaction on this publisher.

Messages published from the same publisher handle after this call are part of the transaction until commit or abort is called.

§Errors

Returns Self::Error when a transaction is already open on this handle (a second begin must not silently join or restart it), or when the broker refuses to start one. A rejected begin must leave an already-open transaction untouched.

Source

fn commit(&self) -> impl Future<Output = Result<(), Self::Error>> + Send

Commits the active transaction, making all buffered messages visible atomically.

§Errors

Returns Self::Error when no transaction is open on this handle, or when the broker rejects the commit. After a failed commit the transaction is closed: the implementation discards or aborts the broker-side transaction rather than leaving it open, and a subsequent begin_transaction either starts a fresh transaction or returns an error - the handle must never wedge permanently. Messages of a failed transaction are lost to this handle; redelivery of the inputs, not resubmission of the buffer, is the recovery path.

Source

fn abort(&self) -> impl Future<Output = Result<(), Self::Error>> + Send

Aborts the active transaction, discarding all buffered messages.

§Errors

Returns Self::Error when no transaction is open on this handle, or when the broker fails to abort.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<M, W, E, Pipe, Body> TransactionalPublisher for Slot<M, W, E, Pipe, Body>
where M: OutSlot, W: TransactionalPublisher, E: Send + Sync, Pipe: OutPipeline<W>,

Source§

impl<P, M> TransactionalPublisher for SlotPublisher<P, M>