March Docs

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

fnbroadcastbroadcast(pubsub_name, topic, message)#

Broadcast message to all subscribers of topic in the named pubsub. Wildcard subscriptions that match topic also receive the message.

fnbroadcast_frombroadcast_from(pubsub_name, from_id, topic, 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.

fnclear_inboxclear_inbox(pubsub_name, subscriber_id)#

Clear the inbox of subscriber_id in the named pubsub.

fninboxinbox(pubsub_name, subscriber_id)#

Return all messages delivered to subscriber_id in the named pubsub. Messages are in delivery order (oldest first).

fnlocal_broadcast_synclocal_broadcast_sync(pubsub_name, topic, message)#

Synchronous local broadcast — identical to broadcast but named to signal that delivery is immediate (no async queuing). Useful for tests.

fnsubscribesubscribe(pubsub_name, topic, subscriber_id)#

Subscribe subscriber_id to topic in the named pubsub instance. If the subscriber is already registered for this topic, this is a no-op.

fnsubscriberssubscribers(pubsub_name, topic)#

Return the list of subscriber IDs registered under the exact topic.

fntopic_matchestopic_matches(pattern, topic)#
fnunsubscribeunsubscribe(pubsub_name, topic, subscriber_id)#

Unsubscribe subscriber_id from topic in the named pubsub instance.