Skip to content

muhannadsalkini/NodeJS-MessageBroker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Message Broker Application

This repository contains a simple message broker application built with Docker, Redis, and Node.js using TypeScript.

Prerequisites

Make sure you have the following installed on your machine:

Getting Started

  1. Clone the Repository:

    git clone https://github.com/muhannadsalkini/NodeJS-MessageBroker
    cd NodeJS-MessageBroker
  2. 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
  3. Install Dependencies:

    npm install
  4. Build TypeScript:

    npm run build
  5. Start the Application:

    npm start

    This will start the server at http://localhost:4000.

  6. Test Route: Open your browser or a tool like Postman and visit http://localhost:4000/. You should see a test message.

Development

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.

API Endpoints

  • Producer Endpoint:

    • Path: /produce
    • Method: POST
    • Request Body:
      {
        "message": "Your message here"
      }
    • Response:
      {
        "success": true,
        "message": "Message produced successfully"
      }
  • 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"
        }

Docker

To run the application using Docker, make sure Docker is installed and then execute the following commands:

  1. 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
    
  2. 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!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published