pub trait QueueDatabase: Database { }Expand description
A sqlx database the inbox runs on: one that binds and reads the values the queue’s own statements use, runs statements on a connection, and reports the rows a statement changed.
Every database whose sqlx driver does so implements it; Postgres, MySQL, SQLite and Any do.
The rows a statement changed come through sqlx’s AnyQueryResult, which every driver in sqlx
converts its result into; a driver outside sqlx provides that conversion for its own result
type.
§Examples
use ruststream_sqlx::prelude::*;
use serde::Deserialize;
use sqlx::{PgPool, Postgres};
#[derive(Inbox, sqlx::FromRow)]
#[inbox(table = "email_jobs")]
pub struct SendEmail {
#[field(id, generated)]
job_id: i64,
#[field(group)]
name: String,
#[field(payload)]
payload: Vec<u8>,
}
#[derive(Deserialize)]
struct Email {
to: String,
}
#[subscriber(InboxQueue::<SendEmail>::new("emails"))]
async fn send(email: &Email) -> HandlerOutcome {
tracing::info!(to = %email.to, "sending");
HandlerOutcome::ack()
}
// `Postgres` is a `QueueDatabase`: the broker over a `PgPool` is a `SqlxBroker<Postgres>`.
pub fn broker(pool: PgPool) -> SqlxBroker<Postgres> {
SqlxBroker::new(pool)
}
pub fn app(pool: PgPool) -> RustStream {
RustStream::new(AppInfo::new("mailer", "0.1.0")).with_broker(broker(pool), |b| {
b.include(send);
})
}Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".