pub struct InboxThreads { /* private fields */ }Expand description
The dedicated threads of an InboxQueue subscription, and the connections each one opens for
its handlers’ queries: what InboxSettings::on_threads
mounts.
A handler on one of the threads queries through Ctx<keys::Pool<..>> on a pool of the
thread’s own, with the service pool’s options and connections
connections at most, one unless set. Its connections open on the thread and close with it.
Knowing both numbers, the subscription counts threads × connections against the broker’s
connection_limit when it opens.
§Examples
use ruststream::nonzero;
use ruststream_sqlx::prelude::*;
use sqlx::{PgPool, Postgres};
#[subscriber(InboxQueue::<LedgerJob>::new("entries"))]
async fn post(entry: &Entry, Ctx(pool): Ctx<keys::Pool<Postgres>>) -> HandlerOutcome {
let posted = sqlx::query("INSERT INTO postings (amount) VALUES ($1)")
.bind(entry.amount)
.execute(&pool)
.await;
if posted.is_ok() { HandlerOutcome::ack() } else { HandlerOutcome::retry() }
}
pub fn app(pool: PgPool) -> RustStream {
// Eight threads, an account's entries on one of them, one connection each.
let threads = InboxThreads::new(nonzero!(8)).by_key();
RustStream::new(AppInfo::new("ledger", "0.1.0")).with_broker(SqlxBroker::new(pool), |b| {
b.include(post.on_threads(threads));
})
}Implementations§
Source§impl InboxThreads
impl InboxThreads
Sourcepub const fn new(count: NonZeroUsize) -> Self
pub const fn new(count: NonZeroUsize) -> Self
count dedicated threads, as threads(count), each opening one connection.
Sourcepub const fn by_key(self) -> Self
pub const fn by_key(self) -> Self
Sends the deliveries of one partition key to one thread, as threads(count, by_key), so
a key keeps its order.
Sourcepub const fn connections(self, connections: NonZeroU32) -> Self
pub const fn connections(self, connections: NonZeroU32) -> Self
Opens connections connections at most on each thread, for its handlers’ queries.
A thread runs its deliveries one at a time, so one connection serves a handler that holds one connection at a time. A handler that holds two at once, or queries from tasks it spawns on its thread, needs one more for each.
Trait Implementations§
Source§impl Clone for InboxThreads
impl Clone for InboxThreads
impl Copy for InboxThreads
Source§impl Debug for InboxThreads
impl Debug for InboxThreads
impl Eq for InboxThreads
Source§impl Hash for InboxThreads
impl Hash for InboxThreads
Source§impl PartialEq for InboxThreads
impl PartialEq for InboxThreads
impl StructuralPartialEq for InboxThreads
Auto Trait Implementations§
impl Freeze for InboxThreads
impl RefUnwindSafe for InboxThreads
impl Send for InboxThreads
impl Sync for InboxThreads
impl Unpin for InboxThreads
impl UnsafeUnpin for InboxThreads
impl UnwindSafe for InboxThreads
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
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
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> ⓘ
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