How evobytes/nats-ws-gateway-and-server works
This repository packages an embedded NATS server with a WebSocket/HTTP gateway. Clients send messages on a topic through WebSockets or HTTP POST; the gateway publishes them to NATS, whose subscriptions deliver messages back to WebSocket clients. A QUERY /status endpoint reports uptime and observed topics. Separate utilities provide traffic logging and basic NATS pub/sub, with sample clients in several languages. The main server excerpt is partial, so some handler wiring and topic-stat recording details are not shown.
Main entry points: nats-ws-gateway-and-server/main.go Embedded NATS · pub.go CLI publisher · sub.go CLI subscriber · nats-ws-gateway-and-server-logger/main.go Traffic logger
Components 16
Gateway
- Gateway server
cmd/nats-ws-gateway-and-server/main.go - WebSocket bridge
cmd/nats-ws-gateway-and-server/main.go - HTTP publish
cmd/nats-ws-gateway-and-server/main.go - Status API
cmd/nats-ws-gateway-and-server/main.go - Topic statistics
cmd/nats-ws-gateway-and-server/main.go - Embedded NATS
cmd/nats-ws-gateway-and-server/main.go
Operations
- Traffic logger
cmd/nats-ws-gateway-and-server-logger/main.go - Traffic log
Client tools
- CLI dispatcher
cmd/nats-ws-gateway-and-server/nats-cli/main.go - CLI connection config
cmd/nats-ws-gateway-and-server/nats-cli/config.go - CLI publisher
cmd/nats-ws-gateway-and-server/nats-cli/pub.go - CLI subscriber
cmd/nats-ws-gateway-and-server/nats-cli/sub.go - Example clients
client-examples
Other components
- WebSocket users
- HTTP callers
- NATS clients
Connections 18
- WebSocket users → WebSocket bridge: connects to
README.md - HTTP callers → HTTP publish: posts messages
cmd/nats-ws-gateway-and-server/main.go - HTTP callers → Status API: queries status
README.md - Gateway server → Embedded NATS: starts and connects
cmd/nats-ws-gateway-and-server/main.go - WebSocket bridge → Embedded NATS: publishes messages
cmd/nats-ws-gateway-and-server/main.go - Embedded NATS → WebSocket bridge: delivers messages
cmd/nats-ws-gateway-and-server/main.go - HTTP publish → Embedded NATS: publishes messages
cmd/nats-ws-gateway-and-server/main.go - Status API → Topic statistics: reads snapshot
cmd/nats-ws-gateway-and-server/main.go - NATS clients → Embedded NATS: connects to
README.md - Traffic logger → Embedded NATS: subscribes to all
cmd/nats-ws-gateway-and-server-logger/main.go - Traffic logger → Traffic log: writes records
cmd/nats-ws-gateway-and-server-logger/main.go - CLI dispatcher → CLI publisher: dispatches publish
cmd/nats-ws-gateway-and-server/nats-cli/main.go - CLI dispatcher → CLI subscriber: dispatches subscribe
cmd/nats-ws-gateway-and-server/nats-cli/main.go - CLI publisher → CLI connection config: resolves URL
cmd/nats-ws-gateway-and-server/nats-cli/pub.go - CLI subscriber → CLI connection config: resolves URL
cmd/nats-ws-gateway-and-server/nats-cli/sub.go - CLI publisher → Embedded NATS: publishes messages
cmd/nats-ws-gateway-and-server/nats-cli/pub.go - CLI subscriber → Embedded NATS: subscribes to subject
cmd/nats-ws-gateway-and-server/nats-cli/sub.go - Example clients → WebSocket bridge: connect over WebSocket
README.md