pub struct ConnectedSqlxBroker<DB: Database, D = BuiltIn<DB>> { /* private fields */ }Expand description
The connected inbox broker: the typed witness that the database answered.
It hands out publishers and opens subscriptions; shutdown stops
its claim loops and the extension of its leases, and refuses every handle it handed out. A
delivery in work keeps its lease after shutdown and settles as before; its lease is no
longer extended. In the advisory lock form shutdown releases the lock of every delivery in
work and returns once no lock of the broker is left; such a delivery’s settlement then fails
with SqlxBrokerError::Closed.
§Examples
use ruststream::OutgoingMessage;
use ruststream_sqlx::prelude::*;
use serde::Serialize;
use sqlx::{PgConnection, PgPool, Postgres};
#[derive(Inbox, sqlx::FromRow)]
#[inbox(table = "cleanup_jobs")]
pub struct Cleanup {
#[field(id, generated)]
id: i64,
#[field(payload)]
payload: Vec<u8>,
}
impl Publish<Postgres> for Cleanup {
async fn publish(
conn: &mut PgConnection,
message: &OutgoingMessage<'_>,
) -> Result<(), sqlx::Error> {
sqlx::query("INSERT INTO cleanup_jobs (payload) VALUES ($1)")
.bind(message.payload())
.execute(conn)
.await?;
Ok(())
}
}
#[derive(Serialize, Outgoing)]
#[outgoing(name = "cleanup")]
struct Sweep {
older_than_days: u32,
}
pub fn app(pool: PgPool) -> RustStream {
RustStream::new(AppInfo::new("maintenance", "0.1.0")).with_broker(SqlxBroker::new(pool), |b| {
// Once the broker connected, the policy pairs against the `ConnectedSqlxBroker` and the
// hook schedules the first sweep.
b.after_startup(Repository::<Cleanup>::default(), async move |cleanups| {
cleanups.message(&Sweep { older_than_days: 30 }).publish().await
});
})
}Trait Implementations§
Source§impl<DB: QueueDatabase, D: Dialect + 'static> ConnectedBroker for ConnectedSqlxBroker<DB, D>
impl<DB: QueueDatabase, D: Dialect + 'static> ConnectedBroker for ConnectedSqlxBroker<DB, D>
Source§fn shutdown(
self,
) -> impl Future<Output = Result<Self::Closed, Self::Error>> + Send
fn shutdown( self, ) -> impl Future<Output = Result<Self::Closed, Self::Error>> + Send
Stops the claim loops and the extension of every lease, and refuses every handle handed out before. A delivery in work in the lease or row lock form settles as before; its lease runs out unless it settles first.
In the advisory lock form it then releases the lock of every delivery in work: each session unlocks its key and goes back to the pool, or closes where the database does not confirm the release. It waits for each session lent to a settlement in flight, and for the sessions still closing after a delivery or a claim was dropped, and returns once no lock of the broker is left. In a service the runtime has stopped its subscriptions by then, and its shutdown timeout bounds the handlers that hold a session.
Source§type Error = SqlxBrokerError
type Error = SqlxBrokerError
Source§impl<DB: QueueDatabase, D: Dialect + 'static> DefaultPublish for ConnectedSqlxBroker<DB, D>
impl<DB: QueueDatabase, D: Dialect + 'static> DefaultPublish for ConnectedSqlxBroker<DB, D>
Source§impl<DB, D, Row> PublishPolicy<ConnectedSqlxBroker<DB, D>> for Repository<Row>
impl<DB, D, Row> PublishPolicy<ConnectedSqlxBroker<DB, D>> for Repository<Row>
Source§type Live = RepositoryPublisher<DB, Row>
type Live = RepositoryPublisher<DB, Row>
Publisher for a leaf policy, or the live
wiring form for a combinator stack (a typed publisher over a policy pairs into the same
typed publisher over the live leaf).Source§fn pair(
self,
connected: &ConnectedSqlxBroker<DB, D>,
) -> impl Future<Output = Result<Self::Live, PairError>> + Send
fn pair( self, connected: &ConnectedSqlxBroker<DB, D>, ) -> impl Future<Output = Result<Self::Live, PairError>> + Send
Source§fn channel_bindings(&self, channel: &str) -> Bindings
fn channel_bindings(&self, channel: &str) -> Bindings
AsyncAPI
document. Read moreSource§fn operation_bindings(&self, channel: &str) -> Bindings
fn operation_bindings(&self, channel: &str) -> Bindings
send operation in the document. Read moreSource§impl<DB: QueueDatabase, D: Dialect + 'static> PublishPolicy<ConnectedSqlxBroker<DB, D>> for Routed
impl<DB: QueueDatabase, D: Dialect + 'static> PublishPolicy<ConnectedSqlxBroker<DB, D>> for Routed
Source§type Live = RoutedPublisher<DB>
type Live = RoutedPublisher<DB>
Publisher for a leaf policy, or the live
wiring form for a combinator stack (a typed publisher over a policy pairs into the same
typed publisher over the live leaf).Source§fn pair(
self,
connected: &ConnectedSqlxBroker<DB, D>,
) -> impl Future<Output = Result<Self::Live, PairError>> + Send
fn pair( self, connected: &ConnectedSqlxBroker<DB, D>, ) -> impl Future<Output = Result<Self::Live, PairError>> + Send
Source§fn channel_bindings(&self, channel: &str) -> Bindings
fn channel_bindings(&self, channel: &str) -> Bindings
AsyncAPI
document. Read moreSource§fn operation_bindings(&self, channel: &str) -> Bindings
fn operation_bindings(&self, channel: &str) -> Bindings
send operation in the document. Read moreSource§impl<DB, D> Subscribe for ConnectedSqlxBroker<DB, D>where
DB: QueueDatabase + RoleColumns,
D: ByName<DB> + 'static,
impl<DB, D> Subscribe for ConnectedSqlxBroker<DB, D>where
DB: QueueDatabase + RoleColumns,
D: ByName<DB> + 'static,
Source§type Subscriber = NamedSubscriber<DB, D>
type Subscriber = NamedSubscriber<DB, D>
Source§type Copies = BrokerMoves
type Copies = BrokerMoves
Source§async fn subscribe(
&self,
name: &str,
) -> Result<Self::Subscriber, SqlxBrokerError>
async fn subscribe( &self, name: &str, ) -> Result<Self::Subscriber, SqlxBrokerError>
Source§fn declare_retry(
&self,
name: &str,
declaration: &RetryDeclaration,
) -> Result<(), DeclareRetryError>
fn declare_retry( &self, name: &str, declaration: &RetryDeclaration, ) -> Result<(), DeclareRetryError>
Source§impl<DB, D, Row, Mode> SubscriptionSource<ConnectedSqlxBroker<DB, D>> for InboxQueue<Row, Mode>where
DB: QueueDatabase,
D: Dialect + Opens<Row::Opening> + 'static,
Row: InboxRow + Events<DB>,
Row::Form: FormOn<D>,
Mode: InboxMode,
impl<DB, D, Row, Mode> SubscriptionSource<ConnectedSqlxBroker<DB, D>> for InboxQueue<Row, Mode>where
DB: QueueDatabase,
D: Dialect + Opens<Row::Opening> + 'static,
Row: InboxRow + Events<DB>,
Row::Form: FormOn<D>,
Mode: InboxMode,
Source§type Subscriber = InboxSubscriber<DB, Row, Mode>
type Subscriber = InboxSubscriber<DB, Row, Mode>
Source§type Copies = BrokerMoves
type Copies = BrokerMoves
AddressedCopies, NamedCopies or BrokerMoves. Read moreSource§async fn subscribe(
self,
connected: &ConnectedSqlxBroker<DB, D>,
) -> Result<Self::Subscriber, SqlxBrokerError>
async fn subscribe( self, connected: &ConnectedSqlxBroker<DB, D>, ) -> Result<Self::Subscriber, SqlxBrokerError>
Source§fn declare_retry(self, declaration: &RetryDeclaration) -> Self
fn declare_retry(self, declaration: &RetryDeclaration) -> Self
Source§fn channel_bindings(&self) -> Bindings
fn channel_bindings(&self) -> Bindings
AsyncAPI document. Read moreSource§fn declare_retry_on(
&self,
_connected: &ConnectedSqlxBroker<DB, D>,
declaration: &RetryDeclaration,
) -> Result<(), DeclareRetryError>
fn declare_retry_on( &self, _connected: &ConnectedSqlxBroker<DB, D>, declaration: &RetryDeclaration, ) -> Result<(), DeclareRetryError>
Source§fn operation_bindings(&self) -> Bindings
fn operation_bindings(&self) -> Bindings
receive operation in the document. Read moreSource§fn message_bindings(&self) -> Bindings
fn message_bindings(&self) -> Bindings
Source§impl<DB: QueueDatabase, D: Dialect + 'static> TestableBroker for ConnectedSqlxBroker<DB, D>
impl<DB: QueueDatabase, D: Dialect + 'static> TestableBroker for ConnectedSqlxBroker<DB, D>
Source§fn install_coordinator(&self, coordinator: Coordinator)
fn install_coordinator(&self, coordinator: Coordinator)
Source§fn inject(&self, message: OutgoingMessage<'_>)
fn inject(&self, message: OutgoingMessage<'_>)
Source§fn published(&self, name: &str) -> Vec<RawMessage>
fn published(&self, name: &str) -> Vec<RawMessage>
name on this broker, in publish order. Backs the
harness’s published::<T>(name) assertions and expect_published.Source§fn backlog(&self) -> Backlog
fn backlog(&self) -> Backlog
Backlog::Missed for publish/subscribe,
Backlog::Delivered for a queue or a log that keeps them. Read moreSource§fn routes(&self, destination: &str, subscriptions: &[&str]) -> Vec<usize>
fn routes(&self, destination: &str, subscriptions: &[&str]) -> Vec<usize>
destination is delivered to,
as the broker’s own routing picks them: the positions in subscriptions (the names the
app subscribed under on this broker) of the ones it delivers to. Read moreAuto Trait Implementations§
impl<DB, D = BuiltIn<DB>> !RefUnwindSafe for ConnectedSqlxBroker<DB, D>
impl<DB, D = BuiltIn<DB>> !UnwindSafe for ConnectedSqlxBroker<DB, D>
impl<DB, D> Freeze for ConnectedSqlxBroker<DB, D>
impl<DB, D> Send for ConnectedSqlxBroker<DB, D>
impl<DB, D> Sync for ConnectedSqlxBroker<DB, D>
impl<DB, D> Unpin for ConnectedSqlxBroker<DB, D>
impl<DB, D> UnsafeUnpin for ConnectedSqlxBroker<DB, D>
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, 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