Liking cljdoc? Tell your friends :D

Real-Time (WebSocket)

The realtime library provides WebSocket-based real-time communication with JWT authentication, message routing, and topic-based pub/sub.

Connection lifecycle

  1. Client connects with JWT: ws://host/ws?token=<jwt>

  2. Server verifies JWT via IJWTVerifier adapter

  3. Connection record created and registered

  4. Client sends and receives messages

  5. On disconnect: cleanup registry, unsubscribe from all topics

Message routing types

TypeTargetUse case

:broadcast

All connections

System announcements

:user

Specific user-id

Direct messages

:role

Users with a specific role

Admin notifications

:connection

Specific connection-id

Job progress updates

Sending messages

(require '[boundary.realtime.ports :as ports])

;; Broadcast to all
(ports/send-to-all service {:type :announcement :text "System maintenance in 5 minutes"})

;; Send to specific user
(ports/send-to-user service user-id {:type :notification :data {...}})

;; Send to all users with a role
(ports/send-to-role service :admin {:type :alert :data {...}})

;; Send to specific connection
(ports/send-to-connection service conn-id {:type :progress :percent 75})

Topic-based pub/sub

;; Subscribe connection to a topic
(ports/subscribe-to-topic pubsub-mgr conn-id "order:123")

;; Publish to all topic subscribers
(ports/publish-to-topic service "order:123" {:type :order-updated :payload {...}})

;; Unsubscribe
(ports/unsubscribe-from-topic pubsub-mgr conn-id "order:123")

Integrant configuration

:boundary/realtime-service
{:jwt-verifier #ig/ref :boundary/jwt-verifier
 :db           #ig/ref :boundary/db}   ; optional, for persistence

See realtime library for the full reference.

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close