This is a sample project for playing with websocket with integration test built in it.
Execute the following command:
$ go test -timeout 30s -parallel 10 ./...
Note:
The
-parallel 10
flag is necessary because the test uses parallel testing to simulate concurrent connections of 10 clients (9 consumers and 1 sender).
- Client connect via websocket to
/messages/listen
(done) - Publisher publishes Messages via HTTP endpoint
POST /messages
- Message will be stored in data store, and then pushed back to the connected clients
- Enable Publisher to publish message by replying to the websocket
- Enable multiple connection per user
- Message order synchronization
Spawning goroutine to send message A (goroutine A) prior to message B (goroutine B) doesn't guarantee that goroutine A will be executed prior to goroutine B.
Spawn a worker (goroutine) within the connection to write message. Message is extracted from internal message queue which guarantees the message order.