pub struct ConfirmsTransaction { /* private fields */ }Expand description
An owned confirm-transaction, opened by
transaction on a ConfirmsPublisher.
A private publish buffer: publish appends to this value rather than
to the publisher, commit flushes the whole buffer on the confirm
channel and awaits every acknowledgement, and abort discards it
without touching the broker. Both settle by consuming self, so a double commit or a publish
after settling is a compile error.
Unlike the handle-level buffer of the borrowed kind, any number of these can be open on one publisher at a time, and the publisher keeps publishing directly while they are.
§Examples
use std::error::Error;
use ruststream_lapin::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize)]
struct Order {
id: u64,
}
// Two transactions open side by side, each settled on its own.
async fn record(
publisher: &impl OwnedTransactions,
order: &Order,
) -> Result<(), Box<dyn Error + Send + Sync>> {
let mut shipment = publisher.owned_transaction().await?;
let mut audit = publisher.owned_transaction().await?;
shipment.publish("shipments", order).await?;
audit.publish("audit", order).await?;
shipment.commit().await?;
audit.commit().await?;
Ok(())
}
#[subscriber("orders")]
async fn ship(order: &Order, Out(publisher): Out<impl OwnedTransactions>) -> HandlerOutcome {
if record(publisher, order).await.is_err() {
return HandlerOutcome::retry();
}
HandlerOutcome::ack()
}
fn app() -> RustStream {
let broker = LapinBroker::new("amqp://localhost:5672");
RustStream::new(AppInfo::new("orders", "0.1.0")).with_broker(broker, |b| {
b.include(ship)
.out(DefaultSlot, TransactionalPublish::default())
.build();
})
}Trait Implementations§
Source§impl Debug for ConfirmsTransaction
impl Debug for ConfirmsTransaction
Source§impl Drop for ConfirmsTransaction
impl Drop for ConfirmsTransaction
Source§impl Transaction for ConfirmsTransaction
impl Transaction for ConfirmsTransaction
Source§type Payload = Take
type Payload = Take
A buffered message is kept until the commit, so the transaction takes the buffer the framework wrote instead of copying out of one it may only read.
Source§type Options = LapinPublishOptions
type Options = LapinPublishOptions
The publisher’s own settings: a buffered message becomes an ordinary publish at the commit, so it honours exactly what one outside the transaction does.
Source§fn publish(
&mut self,
msg: OutgoingFor<'_, Take>,
options: Option<&Self::Options>,
) -> impl Future<Output = Result<(), Self::Error>>
fn publish( &mut self, msg: OutgoingFor<'_, Take>, options: Option<&Self::Options>, ) -> impl Future<Output = Result<(), Self::Error>>
Source§async fn commit(self) -> Result<(), Self::Error>
async fn commit(self) -> Result<(), Self::Error>
Publishes the buffered messages in order and awaits every confirm.
§Errors
Returns AmqpError::Closed once the broker has shut down, and AmqpError::Publish
when a message fails to publish or the broker returns a negative confirm. A failed commit
has still consumed the transaction and its buffer is lost: redelivery of the inputs, not
resubmission of the buffer, is the recovery path. Messages already flushed stay
published - publisher confirms give durability per message, not atomicity across them
(use ServerTxPublish for that).
§Cancel safety
Not cancel safe: dropping the future mid-flush leaves an unknown prefix of the buffer published.
Auto Trait Implementations§
impl !RefUnwindSafe for ConfirmsTransaction
impl !UnwindSafe for ConfirmsTransaction
impl Freeze for ConfirmsTransaction
impl Send for ConfirmsTransaction
impl Sync for ConfirmsTransaction
impl Unpin for ConfirmsTransaction
impl UnsafeUnpin for ConfirmsTransaction
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more