PStream is a high-performance streaming server implementation in Go that provides WebSocket-based pub/sub functionality with built-in metrics using Prometheus.
- WebSocket-based streaming server
- Producer/Consumer pattern implementation
- In-memory message storage
- Prometheus metrics integration
- Concurrent message handling
- Easy to extend and customize
- Go 1.21 or higher
- Make (for build automation)
Clone the repository:
git clone https://github.com/yourusername/PStream.git
cd PStreamInstall dependencies:
go mod downloadTo start the server:
make runOr manually:
go run main.goThe server will start on port 3000 by default.
main.go- Entry point of the applicationserver.go- WebSocket server implementationproducer.go- Message producer implementationconsumer.go- Message consumer implementationstorage.go- Message storage interface and implementationtypes.go- Common types and interfacescmd/- Command-line tools and utilities
The server can be configured using the Config struct:
cfg := &Config{
ListenAddr: ":3000",
StoreProducerFunc: func() Storer {
return NewMemoryStore()
},
}/ws/producer- Endpoint for message producers/ws/consumer- Endpoint for message consumers
Prometheus metrics are available at /metrics endpoint, providing:
- Message throughput
- Connection statistics
- System metrics
make testmake build