graphql-server.subscriptions
Topic-based pub/sub subscription infrastructure using core.async channels.
Provides a pluggable ISubscriptionManager protocol for managing GraphQL subscriptions. Topics are vectors like [:game game-id] or [:lobby]. Subscribers receive core.async channels that emit messages published to their topic.
The default CoreAsyncSubscriptionManager implementation uses sliding buffers to prevent slow consumers from blocking publishers. Users can implement their own subscription manager (Redis, Kafka, etc.) by implementing the ISubscriptionManager protocol.
create-subscription-manager
(create-subscription-manager)Creates a new CoreAsyncSubscriptionManager.
The subscription manager uses an atom to track subscriptions and core.async channels with sliding buffers for message delivery.
ISubscriptionManager
protocol
Protocol for managing pub/sub subscriptions.
Implementations handle the mechanics of tracking subscribers and delivering messages. The protocol is transport-agnostic - implementations can use core.async, Redis pub/sub, Kafka, or any other messaging system.
members
publish!
(publish! this topic message)Publishes a message to all subscribers of a topic.
Non-blocking - messages are offered to subscriber channels. If a subscriber’s buffer is full, the message may be dropped (sliding buffer) or the oldest message discarded. Returns nil.
subscribe!
(subscribe! this topic)Subscribes to a topic and returns a core.async channel.
The returned channel receives all messages published to the topic. Implementations should use buffered channels to prevent slow consumers from blocking publishers. Returns the subscription channel.
subscriber-count
(subscriber-count this topic)Returns the number of active subscribers for a topic.
Returns 0 if the topic has no subscribers.
topics
(topics this)Returns a sequence of all topics with active subscribers.
unsubscribe!
(unsubscribe! this topic channel)Unsubscribes a channel from a topic.
Closes the channel and removes it from the subscription list. Safe to call multiple times. Returns nil.
Message
A message published to subscribers. Contains a :type keyword and optional :data payload.
Topic
A topic is a vector identifying what to subscribe to. Examples: [:game game-id], [:lobby], [:user user-id :notifications]