Skip to main content

Parameters

A destination declared as a name template becomes a channel whose address keeps its placeholders, each one declared as a parameter.

#[outgoing(name = "orders.{tenant}.accepted")] declares a name template. The template is the channel's id and its address. Each {placeholder} is an entry of the channel's parameters. The document names the segments; what a service puts in them is run-time data and is not listed. A type reaches the document where it is published: each type of an Out slot's #[publishes(..)] list gets a send operation on its channel. A type with no declared destination contributes no channel, since each call site names its own. Without the macros the slot's OutSlot::outgoing returns the list, and OutgoingMessageMetadata::with_parameters names the placeholders. The example runs with cargo test --example asyncapi_reports --features macros,memory,asyncapi.

Example​

/// An order accepted for one tenant: the tenant is a segment of the channel's name.
#[derive(Debug, Serialize, Outgoing, JsonSchema)]
#[outgoing(name = "orders.{tenant}.accepted")]
struct Accepted {
id: u64,
}

#[derive(OutSlot)]
#[publishes(Accepted)]
struct Tenants;

#[subscriber("orders")]
async fn accept(order: &Order, Out(tenants): Out<impl Publisher, Tenants>) -> HandlerOutcome {
let accepted = Accepted { id: order.id };
match tenants
.message(&accepted)
.to()
.tenant(&order.tenant)
.publish()
.await
{
Ok(()) => HandlerOutcome::ack(),
Err(_) => HandlerOutcome::retry(),
}
}