Rust

store

Module

The subscription store: a topic-filter trie that resolves a publish to its subscribers in one walk.

Contents

use utopia_mqtt::Record;
Rust
pub struct Record

What the store knows of one connection: the isolation key and user it subscribed under, and its subscriptions.

use utopia_mqtt::Store;
Rust
pub struct Store

A topic-filter trie for MQTT subscriptions, indexed by a prefix (an isolation key: a tenant, a project) and then by topic level, so a publish finds every matching filter (+ one level, # the rest) in one walk.

Text
root -> prefix -> "test" -> "hello" -> fds: {11: 1}
                         -> "#"     -> fds: {12: 1}

A wildcard filter that does not itself start with $ never matches a topic whose first level does ($SYS/..., MQTT 4.7.2).

Rust
use utopia_mqtt::Store;

let mut store = Store::new();
store.subscribe(b"proj", b"user", b"test/+", 11, 1);
store.subscribe(b"proj", b"user", b"test/#", 12, 0);
store.subscribe(b"other", b"user", b"test/hello", 13, 1);

let subscribers = store.subscribers(b"proj", b"test/hello");
assert_eq!(subscribers.into_iter().collect::<Vec<_>>(), [(12, 0), (11, 1)]);
Rust
pub type Subscribers = IndexMap<i64, u8, RandomState>

Subscribers by connection, each with its granted QoS, in the order they were found.