跳到主要内容
本页尚未翻译

下面显示的是英文原文。

FilePublish

A file publish appends under the destination's stream key and flushes, so a live subscriber or another reader sees it once the call returns.

FilePublish, Publish in file::prelude, pairs into a FilePublisher on the file the broker opened. A publish appends the message under its stream key and flushes it to the file, so the bytes have reached the operating system when the call returns. A live subscription of that key reads the message next, and so does another process that reads the same file. The file is synced to the storage device when the broker shuts down. Publishes into one file go one at a time, across every broker of the process opened on that path. A stream key is a place inside the file, so the destination is the key alone and the path is named once, in FileBroker::new. The file client caps a stream file at 16 GiB: a publish that reaches the cap fails with SeaFileError::Publish, and every later publish to that file returns that error at once. A publisher kept from before the shutdown returns SeaFileError::NotConnected. A hook registered with after_startup runs once the subscriptions are open, and a hook that returns an error stops the startup.

Example​

The service leaves a record under lifecycle each time it starts.

/// The record a service leaves in the file each time it starts.
#[derive(Debug, PartialEq, Deserialize, Serialize, Outgoing)]
#[outgoing(name = "lifecycle")]
struct Started {
service: String,
}

#[ruststream::app]
fn app() -> impl App {
RustStream::new(AppInfo::new("shipping", "0.1.0")).with_broker(
FileBroker::new("/var/lib/shop/orders.ss"),
|b| {
b.include(ship);
// Runs once the subscriptions are open; a refused append fails the startup.
b.after_startup(Publish, async move |file| {
file.message(&Started {
service: "shipping".to_owned(),
})
.publish()
.await
});
},
)
}