Перейти к основному содержимому
Эта страница ещё не переведена

Ниже показан английский оригинал.

Prelude

Glob file::prelude on a stream file, stdio::prelude on a pipeline, and the crate prelude only in a service that uses both.

Each glob carries the core's own prelude, so #[subscriber], RustStream, HandlerOutcome and Out come with it. use ruststream_sea_file::file::prelude::*; adds FileBroker, the descriptor FileStream, the positions FilePosition, the context keys Position and SeekHandle, and the publish policy as Publish. use ruststream_sea_file::stdio::prelude::*; adds StdioBroker and its policy as Publish.

Publish is the name every broker crate gives its publish policy, so a mount site reads the same on every transport. Moving a service from one transport to the other changes the glob and the broker, and leaves the mount sites alone.

The two transports would claim the same name Publish, so the crate prelude carries neither. A service on both brokers globs it and writes the prefixed FilePublish and StdioPublish.

Example​

One service records orders from a stream file and answers orders read on standard input.

use ruststream_sea_file::prelude::*;

#[subscriber(FileStream::new("orders"), reply("receipts"))]
async fn record(order: &Order) -> Receipt {
Receipt { order: order.id }
}

#[subscriber("orders", reply("receipts"))]
async fn answer(order: &Order) -> Receipt {
Receipt { order: order.id }
}

#[ruststream::app]
fn app() -> impl App {
RustStream::new(AppInfo::new("orders", "0.1.0"))
.with_broker(FileBroker::new("/var/lib/orders/orders.ss"), |b| {
b.include(record).out_reply(FilePublish);
})
.with_broker(StdioBroker::new(), |b| {
b.include(answer)
.out_reply(StdioPublish)
.out_retry(StdioPublish)
.to("orders.retry");
})
}