swarm-queue-client: drop notices::PREFIX, reuse STREAM
This commit is contained in:
parent
e44ea9d8d4
commit
044e4020fa
1 changed files with 12 additions and 11 deletions
|
|
@ -33,20 +33,21 @@ use crate::Error;
|
||||||
/// which stream a notice actually landed in.
|
/// which stream a notice actually landed in.
|
||||||
pub const STREAM: &str = "hive-notices";
|
pub const STREAM: &str = "hive-notices";
|
||||||
|
|
||||||
/// Every hive's notices land under this subject prefix, one subject per
|
/// Build the subject a given hive's notices publish to.
|
||||||
/// hive: `hive-notices.<hiveName>`.
|
///
|
||||||
|
/// Every hive's notices land under `STREAM`, one subject per hive:
|
||||||
|
/// `hive-notices.<hiveName>`.
|
||||||
///
|
///
|
||||||
/// Not one subject per notice *kind* — a consumer that wants a specific
|
/// Not one subject per notice *kind* — a consumer that wants a specific
|
||||||
/// hive's notices subscribes to `notices_subject(hive)`; one that wants
|
/// hive's notices subscribes to `subject(hive)`; one that wants the whole
|
||||||
/// the whole swarm's subscribes to `{PREFIX}.>`. The kind travels inside
|
/// swarm's subscribes to `{STREAM}.>`. The kind travels inside the message
|
||||||
/// the message payload instead, so adding a new notice kind is never a
|
/// payload instead, so adding a new notice kind is never a subject-design
|
||||||
/// subject-design change.
|
/// change. Deliberately reuses `STREAM` rather than a second `PREFIX`
|
||||||
const PREFIX: &str = "hive-notices";
|
/// constant with the same value — one name for one fact, same reasoning
|
||||||
|
/// the module doc above gives for a shared `const` over a repeated literal.
|
||||||
/// Build the subject a given hive's notices publish to.
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn subject(hive: &str) -> String {
|
pub fn subject(hive: &str) -> String {
|
||||||
format!("{PREFIX}.{hive}")
|
format!("{STREAM}.{hive}")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Open the notices stream, creating it if nothing has yet.
|
/// Open the notices stream, creating it if nothing has yet.
|
||||||
|
|
@ -77,7 +78,7 @@ pub async fn open_or_create(
|
||||||
js.create_stream(async_nats::jetstream::stream::Config {
|
js.create_stream(async_nats::jetstream::stream::Config {
|
||||||
name: STREAM.to_owned(),
|
name: STREAM.to_owned(),
|
||||||
description: Some("Lifecycle notices offered by each hive".to_owned()),
|
description: Some("Lifecycle notices offered by each hive".to_owned()),
|
||||||
subjects: vec![format!("{PREFIX}.>")],
|
subjects: vec![format!("{STREAM}.>")],
|
||||||
max_age: std::time::Duration::from_hours(30 * 24),
|
max_age: std::time::Duration::from_hours(30 * 24),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue