pub struct Transactional;Expand description
A subscription whose handler writes through the delivery’s transaction, which acknowledgement commits.
The mount-site step transactional switches a registration to
it: the handler then takes the transaction with Ctx<keys::Tx<DB>>.
§Examples
use ruststream_sqlx::prelude::*;
use sqlx::{PgPool, Postgres};
#[derive(Inbox, sqlx::FromRow)]
#[inbox(table = "signup_jobs")]
pub struct Signup {
#[field(id)]
id: i64,
#[field(payload)]
payload: Vec<u8>,
}
#[derive(serde::Deserialize)]
struct Account {
email: String,
}
#[subscriber(InboxQueue::<Signup>::new("signups"))]
async fn open_account(account: &Account, Ctx(mut tx): Ctx<keys::Tx<Postgres>>) -> HandlerOutcome {
let opened = sqlx::query("INSERT INTO accounts (email) VALUES ($1)")
.bind(&account.email)
.execute(&mut *tx)
.await;
if opened.is_ok() { HandlerOutcome::ack() } else { HandlerOutcome::retry() }
}
pub fn app(pool: PgPool) -> RustStream {
RustStream::new(AppInfo::new("accounts", "0.1.0")).with_broker(SqlxBroker::new(pool), |b| {
// The registration's `InboxQueue<Signup, Plain>` becomes
// `InboxQueue<Signup, Transactional>`.
b.include(open_account.transactional());
})
}Trait Implementations§
Source§impl Clone for Transactional
impl Clone for Transactional
impl Copy for Transactional
Source§impl Debug for Transactional
impl Debug for Transactional
Source§impl Default for Transactional
impl Default for Transactional
impl Eq for Transactional
Source§impl Hash for Transactional
impl Hash for Transactional
Source§impl PartialEq for Transactional
impl PartialEq for Transactional
impl StructuralPartialEq for Transactional
Auto Trait Implementations§
impl Freeze for Transactional
impl RefUnwindSafe for Transactional
impl Send for Transactional
impl Sync for Transactional
impl Unpin for Transactional
impl UnsafeUnpin for Transactional
impl UnwindSafe for Transactional
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.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