BastionPubSub
BastionPubSub: named PubSub instances with wildcard topic matching.
Extends the core PubSub model with:
- Named instances, each identified by a String name.
- Vault-backed storage so everything is testable in pure mode.
- Wildcard topic matching: a subscription topic ending with "*" matches
any broadcast topic that shares the prefix before the "*".
- Delivery queue stored in Vault for testing without an actor runtime.Storage layout (all keys live in a single Vault table per pubsub_name): "sub:<topic>" → List(String) — subscriber IDs for exact topic "inbox:<subscriber_id>" → List(String) — delivered message strings
The "sub:" family stores subscriber IDs as plain strings. Wildcard subscriptions are stored under their literal pattern key, e.g. "sub:room:". When broadcasting to "room:lobby", the code checks every stored subscription key for a pattern match.
Functions
Broadcast message to all subscribers of topic in the named pubsub. Wildcard subscriptions that match topic also receive the message.
Broadcast message to all subscribers of topic, excluding from_id. Useful for channel fan-out where the sender should not receive their own message.
Clear the inbox of subscriber_id in the named pubsub.
Return all messages delivered to subscriber_id in the named pubsub. Messages are in delivery order (oldest first).
Synchronous local broadcast — identical to broadcast but named to signal that delivery is immediate (no async queuing). Useful for tests.
Subscribe subscriber_id to topic in the named pubsub instance. If the subscriber is already registered for this topic, this is a no-op.
Return the list of subscriber IDs registered under the exact topic.
Unsubscribe subscriber_id from topic in the named pubsub instance.