This project demonstrates a WebSocket broadcasting application with multi-processing capabilities using Fiber and RabbitMQ as the message broker. It allows multiple processes to handle WebSocket connections and efficiently broadcast messages to connected clients.
Please note that the project uses the following technologies:
- Go-Fiber: A fast and efficient web framework for Go.
- RabbitMQ: A powerful and flexible open-source message broker.
Before running the application, ensure you have the following installed:
- Go (1.16 or higher): https://golang.org/dl/
- RabbitMQ Server: https://www.rabbitmq.com/download.html
- Clone this repository to your local machine:
git clone https://github.com/onionj/websocket-broadcasting.git
cd websocket-broadcasting
- Fetch the required dependencies using Go Modules:
go mod download
Ensure you have RabbitMQ running on your local machine or update the configuration settings in config.json
to match your RabbitMQ server.
To run the WebSocket broadcasting application, use the following command:
go run main.go
The application will start, and you can visit http://localhost:8080
in your browser to interact with the WebSocket server.
The application uses Fiber to handle incoming WebSocket connections and messages. When a WebSocket connects, the server add it to a list.
Each process has a queue bound to a FANOUT exchange. When a message is pushed to the exchange, all queues receive the message, and each process sends the message to the connected websockets.