Skip to content

Elysia Örneği: Micro Socket Gateway

Elysia (Bun) ile yazılmış tam bir Micro Socket gateway: WebSocket uç noktaları (/ws, /ws/sub/:topic), sub-socket modeli, milyonlarca aboneliğe ölçeklenebilir yayın.


Genel Bakış

Örnek proje: examples/elysia-micro-socket/.

  • WebSocket: /ws (çok topic) ve /ws/sub/:topic (sub WebSocket — bağlantı başına tek topic).
  • Sub-socket store: Map<topic, Set<connectionId>>; topic başına O(abone) yayın.
  • Omurga: Bellek içi (tek düğüm); yatay ölçek için NATS/Kafka.
  • Dedup (I₂): messageId ile kullanıcı bazlı; production’da Redis.
  • Demo auth: Boş olmayan token → userId; production’da JWT + ACL.

Çalıştırma

bash
cd examples/elysia-micro-socket
bun install
bun run dev
KaynakURL
Döküman + WS istek athttp://localhost:3000/docs — Connect ile WS bağlan, setup/subscribe/publish gönder, yanıtlar logda
OpenAPI (Scalar)http://localhost:3000/openapi
WebSocket (çok topic)ws://localhost:3000/ws
WebSocket (sub)ws://localhost:3000/ws/sub/prices (örnek)
İstatistikGET http://localhost:3000/stats
Demo yayınGET http://localhost:3000/demo/publish/:topic?key=value

WebSocket ile istek atma

  1. http://localhost:3000/docs aç.
  2. WebSocket bölümünde URL seç: /ws veya /ws/sub/prices (preset butonları) veya kendi URL’ini yaz.
  3. ConnectMessage: setup seç, token gir, Send. Logda ready (ve varsa subscribed) görünür.
  4. subscribe / unsubscribe / publish seçip alanları doldur, Send ile istek at; yanıtlar logda (← yeşil) görünür.

Protokol (Özet)

İstemci → SunucuSunucu → İstemci
setup + token (+ isteğe bağlı topics)ready + sessionId, subscribed (URL/topics için)
subscribe + topicsubscribed + topic
unsubscribe + topicunsubscribed + topic
publish + topic, messageId, payloadack + messageId, status (ok | duplicate)
message + topic, seqNo, messageId, data
error + code, message

Tam referans (HTTP endpoint’leri, tüm mesaj tipleri, mimari): İngilizce sayfa.

Star the repo on GitHub if this documentation is useful — link in the navbar above.