Ниже показан английский оригинал.
Channels
A FileStream subscription and a file publish describe their channel with the stream key; bare keys and stdio describe nothing.
A subscription opened through FileStream reports the stream key it reads, as { "x-ruststream-file": { "streamKey": "orders" } } in the channel's bindings.
A subscription opened by a bare stream key, #[subscriber("orders")], carries no descriptor, so its channel has no bindings.
That is every stdio subscription, and a file subscription mounted without FileStream.
A channel the service publishes to on a stream file carries the same extension, with the destination the mount site resolved: a reply's stream key, an Out slot's, the dead-letter one.
One stream key is both ends of the file, so a channel reads the same whether the service reads it or appends to it.
A stdio publish describes nothing, as a stdio subscription does.
The path of the file stays on the server.
Example
The channels orders and receipts carry their stream keys.
The stdio channels lines and lines.out have no bindings.
- Macros
- Manual
/// Reads `orders` through the descriptor and appends a receipt under `receipts`.
#[subscriber(FileStream::new("orders"), reply("receipts"))]
async fn record(order: &Order) -> Receipt {
Receipt { order: order.id }
}
/// Reads `lines` on standard input by its bare stream key and answers under `lines.out`.
#[subscriber("lines", reply("lines.out"))]
async fn tee(order: &Order) -> Receipt {
Receipt { order: order.id }
}
/// Reads `orders` through the descriptor and appends a receipt under `receipts`.
struct Record;
impl Handle<Order, Receipt> for Record {
fn handle(
&self,
order: &Order,
_outs: &(),
_ctx: &mut Context<'_>,
) -> impl Future<Output = Result<Receipt, HandlerOutcome>> {
ready(Ok(Receipt { order: order.id }))
}
}
/// Reads `lines` on standard input by its bare stream key and answers under `lines.out`.
struct Tee;
impl Handle<Order, Receipt> for Tee {
fn handle(
&self,
order: &Order,
_outs: &(),
_ctx: &mut Context<'_>,
) -> impl Future<Output = Result<Receipt, HandlerOutcome>> {
ready(Ok(Receipt { order: order.id }))
}
}