-
git clone https://github.com/DevItaliya22/PUB-SUB-2 docker-compose build docker-compose up
-
Navigate to the client directory:
cd client
-
Install dependencies:
npm install
-
Start the development server:
npm run dev
The client will be available at
http://localhost:5173
.
-
Navigate to the backend directory:
cd backend
-
Install dependencies:
npm install
-
Start the backend server:
npm start
The backend server will be available at
http://localhost:3000
.
-
Navigate to the root directory containing
docker-compose.yml
: -
Build and start the services using Docker Compose:
docker-compose build docker-compose up
This command builds the Docker images (if necessary) and starts all services defined in the
docker-compose.yml
file. The application will start with the backend server, Redis, and the client.
Make sure Docker and Docker Compose are installed on your system to use the docker-compose
commands.
This project is a React application for a pub-sub game with real-time updates using socket.io
. It allows users to create and join game sessions, and view real-time updates of participants in the game.
- Home Page: Options to join or create a game session.
- Create Page: Generates a unique game ID and navigates to the game session as a player.
- Game Page: Displays game information, including the game ID and socket ID, and allows interaction (e.g., incrementing a counter) based on the user's mode (player or observer).
- React: Front-end library for building the user interface.
- React Router: For routing and navigation within the app.
- Socket.IO: For real-time communication between the client and server.
-
Clone the Repository
git clone <repository-url> cd <project-directory>
-
Install Dependencies
Make sure you have Node.js installed. Then, run:
npm install
-
Development Mode
To start the development server, run:
npm run dev
The app will be available at
http://localhost:5173
. -
Build for Production
To create a production build, run:
npm run build
This will generate a
dist
folder with the production assets. -
Run the Production Build
If you want to serve the production build locally, make sure you have
serve
installed globally:npm install -g serve
Then run:
serve -s dist -l 5173
The app will be available at
http://localhost:5173
.
Here’s how you can set up a Dockerfile for the React client:
# Use the official Node.js image as a base image
FROM node:18-alpine
# Set the working directory
WORKDIR /app
# Install global dependencies
RUN npm install -g serve
# Copy package.json and install dependencies
COPY package.json ./
RUN npm install
# Copy the application code
COPY . .
# Build the React application
RUN npm run build
# Expose the port
EXPOSE 5173
# Serve the application
CMD ["serve", "-s", "dist", "-l", "5173"]
Create a docker-compose.yml
file in the root directory to define and run multi-container Docker applications:
version: '3.8'
services:
client:
build:
context: .
dockerfile: Dockerfile
ports:
- "5173:5173"
- Socket Connection: Ensure that the server (backend) is running on
http://localhost:3000
or update the URL in theGame
component if the backend server URL changes. - Environment Variables: If needed, create a
.env
file for environment-specific configurations.
This project is licensed under the MIT License.
For questions or support, please contact [email protected].
Here’s a README.md
file specifically for the server part of your project:
This server application handles real-time communication for a pub-sub game application. It uses Node.js, Express, Redis, and Socket.IO to provide a robust backend for managing game sessions, user subscriptions, and real-time updates.
- Pub-Sub Management: Manages user subscriptions and message publishing using Redis.
- WebSocket Integration: Provides real-time updates through Socket.IO.
- Job Queues: Handles subscription and publication tasks using BullMQ.
- Node.js: Runtime environment for executing JavaScript code.
- Express: Web framework for Node.js.
- Redis: In-memory data structure store for pub-sub messaging.
- Socket.IO: Real-time communication library for WebSocket.
- BullMQ: Job and queue management library.
-
Clone the repository:
git clone https://github.com/DevItaliya22/PUB-SUB-2 cd backend
-
Install dependencies:
npm install
-
Start the server:
docker run -p 6379:6379 redis docker ps docker exec -it redis_container_id /bin/bash npm run dev
The backend server will be available at
http://localhost:3000
.
- GET
/
: A test endpoint to check if the server is running.
connection
: Triggered when a client connects.subscribe
: Subscribe a user to a game.unsubscribe
: Unsubscribe a user from a game.publish
: Publish an update to a game.message
: Log any received messages.
subscribeQueue
: Processes user subscriptions to games.unsubscribeQueue
: Processes user unsubscriptions from games.publishQueue
: Processes publishing updates to games.
To containerize the server application, ensure Docker and Docker Compose are installed. Dockerfiles for the server are provided in the project directory.
- Socket Connection: Ensure the WebSocket server is correctly configured and running.
- Redis: Make sure Redis is operational and accessible at the specified URL.
This project is licensed under the MIT License.
For questions or support, please contact [email protected].