https://github.com/bluebrown/go-sse
Server sent events implementation in go using redis as broker between backend instances.
https://github.com/bluebrown/go-sse
go redis server-sent-events
Last synced: 6 months ago
JSON representation
Server sent events implementation in go using redis as broker between backend instances.
- Host: GitHub
- URL: https://github.com/bluebrown/go-sse
- Owner: bluebrown
- Created: 2022-01-24T21:53:19.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-01-24T21:58:33.000Z (over 3 years ago)
- Last Synced: 2025-02-07T11:53:35.006Z (8 months ago)
- Topics: go, redis, server-sent-events
- Language: Go
- Homepage:
- Size: 10.7 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Go SSE
Server Sent Events backend written in go. Redis is used to distribute published messages across all backends so that the backend can be scaled horizontally.
The backend is stateless in that it doesn't matter to which instance the message is published, since it will be distributed to all other instances and them sent to the connected clients of the respective instance using event-stream.
## Docker Compose
Start the compose stack, then visit the webpage at http://localhost:8080. It is a basic chat page. Open it multiple times to see real time events published from one client on all other client pages.
```bash
docker-compose up
```## Example Output
```bash
backend_2 | client connected: 192.168.16.2:37712
backend_1 | client connected: 192.168.16.2:47996
backend_2 | 2022/01/23 23:01:44 publishing message: {"user":"John","message":"Hi"}
backend_2 | 2022/01/23 23:01:44 receiving message: {"user":"John","message":"Hi"}
backend_1 | 2022/01/23 23:01:44 receiving message: {"user":"John","message":"Hi"}
backend_2 | 2022/01/23 23:01:53 publishing message: {"user":"Maria","message":"Hello :)"}
backend_1 | 2022/01/23 23:01:53 receiving message: {"user":"Maria","message":"Hello :)"}
backend_2 | 2022/01/23 23:01:53 receiving message: {"user":"Maria","message":"Hello :)"}
```