existing_only
existing_only makes startup fail when the stream file is missing, for a service that reads a file another process writes.
Without the setting, startup creates a missing file and the service reads an empty log.
For a reader that is the wrong answer: a mistyped path, or a writer that has not run yet, leaves it with nothing to read and no error.
With the setting, startup fails with SeaFileError::Connect, which names the path, and no file is created.
A file that is there opens as usual.
In a TestApp test the stream file is a log in memory, and it counts as the file the operator provisioned.
So the refusal shows only against a real file, with TestApp::start_live.
Example
The auditor reads the orders the order service writes to its file. The test starts the auditor on a missing path, and startup fails; once the order service has created the file, the auditor starts and reads it.
- Macros
- Manual
/// A reader of the file the order service writes: it never creates the file itself.
fn reader(path: &str) -> impl App<State = ()> {
let broker = FileBroker::new(path).existing_only();
RustStream::new(AppInfo::new("auditor", "0.1.0")).with_broker(broker, |b| {
b.include(audit);
})
}
#[ruststream::app]
fn app() -> impl App<State = ()> {
reader("/var/lib/orders/orders.ss")
}
/// A reader of the file the order service writes: it never creates the file itself.
fn reader(path: &str) -> impl App<State = ()> {
let broker = FileBroker::new(path).existing_only();
RustStream::new(AppInfo::new("auditor", "0.1.0")).with_broker(broker, |b| {
b.include(subscriber(FileStream::new("orders"), Audit).build());
})
}
fn app() -> impl App<State = ()> {
reader("/var/lib/orders/orders.ss")
}