pub struct Tx<DB>(/* private fields */);Expand description
The delivery’s transaction: the handler’s first Ctx, on a registration mounted with
.transactional().
It reads TxContext and yields Tx, which goes back to the delivery when the
handler ends. A handler reads it once: a second read for one delivery panics, the transaction
lent already.
§Examples
use ruststream_sqlx::prelude::*;
use sqlx::{PgPool, Postgres};
#[subscriber(InboxQueue::<Job>::new("shipments"))]
async fn ship(shipment: &Shipment, Ctx(mut tx): Ctx<keys::Tx<Postgres>>) -> HandlerOutcome {
let shipped = sqlx::query("UPDATE orders SET shipped = true WHERE id = $1")
.bind(shipment.order)
.execute(&mut *tx)
.await;
if shipped.is_ok() { HandlerOutcome::ack() } else { HandlerOutcome::retry() }
}
pub fn app(pool: PgPool) -> RustStream {
RustStream::new(AppInfo::new("shipping", "0.1.0")).with_broker(SqlxBroker::new(pool), |b| {
b.include(ship.transactional());
})
}Trait Implementations§
Source§impl<DB: QueueDatabase> ContextField for Tx<DB>
impl<DB: QueueDatabase> ContextField for Tx<DB>
impl<DB> Copy for Tx<DB>
Auto Trait Implementations§
impl<DB> Freeze for Tx<DB>
impl<DB> RefUnwindSafe for Tx<DB>
impl<DB> Send for Tx<DB>
impl<DB> Sync for Tx<DB>
impl<DB> Unpin for Tx<DB>
impl<DB> UnsafeUnpin for Tx<DB>
impl<DB> UnwindSafe for Tx<DB>
Blanket Implementations§
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<K> CtxKey for Kwhere
K: ContextField,
impl<K> CtxKey for Kwhere
K: ContextField,
Source§type Value = <K as ContextField>::Value
type Value = <K as ContextField>::Value
The owned value the extractor binds.
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
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> ⓘ
Converts
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> ⓘ
Converts
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