feat(go-api): WebSocket endpoint with Redis Streams fan-out#32
Open
Depo-dev wants to merge 4 commits into
Open
feat(go-api): WebSocket endpoint with Redis Streams fan-out#32Depo-dev wants to merge 4 commits into
Depo-dev wants to merge 4 commits into
Conversation
Uses github.com/gorilla/websocket (vs golang.org/x/net/websocket): gorilla has built-in ping/pong control frames, is production-hardened, and has a stable well-documented API. Hub tracks all active Client connections with a RWMutex. Each Client spawns three goroutines: a drain reader (required to receive pong frames), a ping ticker (30s interval, 60s pong timeout), and a Redis XREAD BLOCK loop that filters by contractId and optional topic0, then writes matching event JSON to the WebSocket. Cleanup via context cancellation on disconnect. 4 hub tests: missing contractId 400, connect/disconnect lifecycle, multiple clients, WebSocket upgrade path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements
GET /wsWebSocket endpoint with per-connection Redis Streams fan-out.Library:
github.com/gorilla/websocket— chosen overgolang.org/x/net/websocketfor built-in ping/pong control frame support, production hardening, and a stable documented API.Architecture
Files
ws/hub.go— Hub with RWMutex-protected client set,Register/Unregister,Handlerws/client.go— Client with Redis fan-out goroutinews/hub_test.go— 4 tests (all pass, go vet clean)Tests
TestHub_missingContractID_returns400TestHub_connectDisconnect_lifecycleTestHub_multipleClientsTestHub_websocketConnect_receivesEventCloses #15