Skip to main content

InboxHeaders

Derive Macro InboxHeaders 

Source
#[derive(InboxHeaders)]
{
    // Attributes available to this derive:
    #[inbox]
    #[field]
    #[sqlx]
}
Expand description

Describes the queue table of a message assembled from it, and implements InboxHeaders for the struct.

The struct takes the table’s attributes and the fields that play a role, as a struct deriving Inbox does; every field without a role is a header (see InboxHeaders). custom(..), payload and headers belong to the message struct, which flattens this one into its #[field(headers)] field. #[inbox(checked, db = ..)] checks the table’s statements at compile time, and the message then reads its rows in a Fetch of its own (the headers layout, checked).

§Examples

use ruststream_sqlx::prelude::*;
use sqlx::PgPool;

#[derive(Debug, Clone, InboxHeaders, sqlx::FromRow)]
#[inbox(table = "order_jobs")]
pub struct OrderHeaders {
    #[field(id, generated)]
    job_id: i64,
    #[field(group)]
    name: String,
    tenant: String,
}

#[derive(Debug, Clone, Inbox, sqlx::FromRow)]
pub struct OrderJob {
    #[field(headers)]
    #[sqlx(flatten)]
    headers: OrderHeaders,
    note: Option<String>,
}

#[subscriber(InboxQueue::<OrderJob>::new("orders"))]
async fn ship(job: &OrderJob) -> HandlerOutcome {
    tracing::info!(tenant = %job.headers.tenant, note = ?job.note, "shipping");
    HandlerOutcome::ack()
}

pub fn app(pool: PgPool) -> RustStream {
    RustStream::new(AppInfo::new("shop", "0.1.0")).with_broker(SqlxBroker::new(pool), |b| {
        b.include(ship);
    })
}

Implemented in ruststream-sqlx-macros and used through ruststream-sqlx.