Skip to main content

Channels

Each InboxQueue channel carries x-ruststream-sqlx: the table it reads, qualified with its schema, and the group its name selects where the table has groups.

The extension holds two fields. table is the table's name, with its schema in front where the description names one (app.email_jobs). group is the subscription's name, present only when the table has a group column: in a table without groups the name addresses the whole table. A channel the service publishes to and a subscription by name carry no extension: a name leads into a table through a route, which the channel does not describe.

Example​

The channel emails reports { "table": "app.email_jobs", "group": "emails" }, and the channel reports reports { "table": "reports" }.

/// One row of `app.email_jobs`: the channel of each subscription names the table and its group.
#[derive(Inbox, sqlx::FromRow)]
#[inbox(table = "email_jobs", schema = "app")]
struct SendEmail {
#[field(id, generated)]
id: i64,
#[field(group)]
name: String,
#[field(payload)]
payload: Vec<u8>,
}

/// One row of `reports`, a table without groups: its channel names the table alone.
#[derive(Inbox, sqlx::FromRow)]
#[inbox(table = "reports")]
struct RenderReport {
#[field(id, generated)]
id: i64,
#[field(payload)]
payload: Vec<u8>,
}

#[subscriber(InboxQueue::<SendEmail>::new("emails"))]
async fn send_email(email: &Email) -> HandlerOutcome {
tracing::info!(to = %email.to, "sending");
HandlerOutcome::ack()
}

#[subscriber(InboxQueue::<RenderReport>::new("reports"))]
async fn render(report: &Report) -> HandlerOutcome {
tracing::info!(month = report.month, "rendering");
HandlerOutcome::ack()
}