macula_gateway_pubsub (macula v0.20.5)
View SourcePub/Sub Handler GenServer - manages topic subscriptions and message routing.
Responsibilities: - Subscribe/unsubscribe streams to topics - Route published messages to matching subscribers - Support wildcard topics (* single-level, ** multi-level) - Track bidirectional mapping (topic ↔ stream) - Monitor stream processes for automatic cleanup
Extracted from macula_gateway.erl (Phase 3)
Summary
Functions
Deliver a message to LOCAL subscribers only (no remote routing). Used by pubsub_route delivery to prevent message amplification. When a message arrives from another node via pubsub_route, it should only be delivered to local subscribers, NOT re-routed to remote subscribers.
Get all topics a stream is subscribed to.
Get all subscribers for a topic (exact and wildcard matches).
Handle stream process death - automatic cleanup.
Publish a message to a topic (routes to matching subscribers).
Start the pub/sub handler with options.
Stop the pub/sub handler.
Subscribe a stream to a topic (supports wildcards). Async (cast) to prevent blocking callers when PubSub is busy.
Unsubscribe a stream from a topic. Async (cast) to prevent blocking callers when PubSub is busy.
Types
Functions
Deliver a message to LOCAL subscribers only (no remote routing). Used by pubsub_route delivery to prevent message amplification. When a message arrives from another node via pubsub_route, it should only be delivered to local subscribers, NOT re-routed to remote subscribers.
Get all topics a stream is subscribed to.
Get all subscribers for a topic (exact and wildcard matches).
Handle stream process death - automatic cleanup.
Publish a message to a topic (routes to matching subscribers).
Start the pub/sub handler with options.
-spec stop(pid()) -> ok.
Stop the pub/sub handler.
Subscribe a stream to a topic (supports wildcards). Async (cast) to prevent blocking callers when PubSub is busy.
Unsubscribe a stream from a topic. Async (cast) to prevent blocking callers when PubSub is busy.