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.
|
||||
pub const STREAM: &str = "hive-notices";
|
||||
|
||||
/// Every hive's notices land under this subject prefix, one subject per
|
||||
/// hive: `hive-notices.<hiveName>`.
|
||||
/// Build the subject a given hive's notices publish to.
|
||||
///
|
||||
/// 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
|
||||
/// hive's notices subscribes to `notices_subject(hive)`; one that wants
|
||||
/// the whole swarm's subscribes to `{PREFIX}.>`. The kind travels inside
|
||||
/// the message payload instead, so adding a new notice kind is never a
|
||||
/// subject-design change.
|
||||
const PREFIX: &str = "hive-notices";
|
||||
|
||||
/// Build the subject a given hive's notices publish to.
|
||||
/// hive's notices subscribes to `subject(hive)`; one that wants the whole
|
||||
/// swarm's subscribes to `{STREAM}.>`. The kind travels inside the message
|
||||
/// payload instead, so adding a new notice kind is never a subject-design
|
||||
/// change. Deliberately reuses `STREAM` rather than a second `PREFIX`
|
||||
/// 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.
|
||||
#[must_use]
|
||||
pub fn subject(hive: &str) -> String {
|
||||
format!("{PREFIX}.{hive}")
|
||||
format!("{STREAM}.{hive}")
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
name: STREAM.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),
|
||||
..Default::default()
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue