The socket_gateway
is a Node.js microservice that acts as a WebSocket gateway for real-time communication in a social media application. It registers with Eureka for service discovery and integrates with Kafka for messaging.
To view all services for this social media system, lets visit: https://github.com/goddie9x?tab=repositories&q=social
- Node.js 18+
- Docker and Docker Compose
- Git
Clone the socket_gateway
repository and its required utilities:
git clone https://github.com/goddie9x/socket_gateway.git
cd socket_gateway
Clone the required social_utils
package as a subdirectory in the project root:
git clone https://github.com/goddie9x/social_utils.git utils
Set up environment variables in a .env
file in the root directory with the following configuration:
APP_NAME=socket-gateway
PORT=3005
KAFKA_CLIENT_HOST=localhost:9092
JWT_SECRET=<your-jwt-secret> # replace with your actual JWT secret
EUREKA_DISCOVERY_SERVER_HOST=localhost
EUREKA_DISCOVERY_SERVER_PORT=8761
IP_ADDRESS=socket-gateway
HOST_NAME=socket-gateway
APP_PATH=/api/v1/socket-gateway
Make sure to replace <your-jwt-secret>
with your actual JWT secret.
Ensure dependencies are installed by running:
npm install
To start the service locally:
npm start
The service will run on http://localhost:3005
by default.
-
Dockerfile:
Create a
Dockerfile
in the project root with the following content:FROM node:18-alpine WORKDIR /usr/src/app COPY package*.json ./ RUN npm install --production COPY . . EXPOSE 3005 CMD ["npm", "start"]
-
Build and Run the Docker Container:
Build and start the Docker container:
docker build -t socket-gateway . docker run -p 3005:3005 --env-file .env socket-gateway
To run socket_gateway
within a Docker Compose setup, include the following service definition:
socket-gateway:
image: socket-gateway
build:
context: .
ports:
- 3005:3005
environment:
- APP_NAME=socket-gateway
- PORT=3005
- KAFKA_CLIENT_HOST=localhost:9092
- JWT_SECRET=<your-jwt-secret> # replace with your actual JWT secret
- EUREKA_DISCOVERY_SERVER_HOST=localhost
- EUREKA_DISCOVERY_SERVER_PORT=8761
- IP_ADDRESS=socket-gateway
- HOST_NAME=socket-gateway
- APP_PATH=/api/v1/socket-gateway
networks:
- social-media-network
Start all services with Docker Compose:
docker-compose up --build
Once running, the socket_gateway
will be available at http://localhost:3005/api/v1/socket-gateway
.
This setup will help you start, configure, and deploy the socket_gateway
service in both local and containerized environments.
- Stop Containers: Use
docker-compose down
to stop all services and remove the containers. - Restart Containers: Run
docker-compose restart
to restart the services without rebuilding the images.
This setup enables seamless orchestration of the social media microservices with an API Gateway for managing external client requests.
Contributions are welcome. Please clone this repository and submit a pull request with your changes. Ensure that your changes are well-tested and documented.
This project is licensed under the MIT License. See LICENSE
for more details.