This repository contains a simple message broker application built with Docker, Redis, and Node.js using TypeScript.
Make sure you have the following installed on your machine:
-
Clone the Repository:
git clone https://github.com/muhannadsalkini/NodeJS-MessageBroker cd NodeJS-MessageBroker
-
Set Up Environment Variables: Create a
.env
file in the root of the project and set the following variables:PORT=4000 REDIS_PASSWORD=your_redis_password REDIS_HOST=your_redis_host
-
Install Dependencies:
npm install
-
Build TypeScript:
npm run build
-
Start the Application:
npm start
This will start the server at
http://localhost:4000
. -
Test Route: Open your browser or a tool like Postman and visit
http://localhost:4000/
. You should see a test message.
For development, you can use the following command to run the application with hot-reloading:
npm run dev
This uses nodemon to automatically restart the server when changes are detected.
-
Producer Endpoint:
- Path:
/produce
- Method:
POST
- Request Body:
{ "message": "Your message here" }
- Response:
{ "success": true, "message": "Message produced successfully" }
- Path:
-
Consumer Endpoint:
- Path:
/consume
- Method:
GET
- Response:
- If a message is available:
{ "success": true, "message": "Your consumed message" }
- If no messages are in the queue:
{ "success": false, "message": "No messages in the queue" }
- If a message is available:
- Path:
To run the application using Docker, make sure Docker is installed and then execute the following commands:
- Set Up Doker File:
Edit the
DokerFile
file in the root of the project and set the following variables:PORT=4000 REDIS_PASSWORD=your_redis_password REDIS_HOST=your_redis_host
- Build The Image and Run
docker build -t message-broker . docker run -p 4000:4000 -d message-broker
This will build a Docker image and run the container on port 4000.
Feel free to customize the application or Docker settings based on your requirements. Happy coding!