Skip to content

tentwinkle/assignment-1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Microservices Messaging Assignment

Overview

This repository contains two Node.js microservices that communicate asynchronously via RabbitMQ.

  • Microservice A (Sender): Exposes an API endpoint (/send) to accept messages and publish them to a RabbitMQ queue.
  • Microservice B (Receiver): Listens to the RabbitMQ queue and processes incoming messages.

Architecture & Design

  • Asynchronous Messaging:
    RabbitMQ is used to decouple the sender and receiver, which enhances scalability and fault tolerance.
  • Decoupling:
    The services run independently and communicate solely via the message broker, making the system more modular.

Setup Instructions

Prerequisites

Setting Up RabbitMQ

Run the following command in the repository root:

docker-compose up -d

This starts RabbitMQ with the AMQP port on 5672 and the management UI on 15672.

Microservice A (Sender)

  1. Navigate to the microservice-a directory:
    cd microservice-a
  2. Install dependencies:
    npm install
  3. Create a .env file (optional) with:
    RABBIT_URL=amqp://localhost
    PORT=3000
    QUEUE=messageQueue
    
  4. Start the service:
    npm start

Microservice B (Receiver)

  1. Navigate to the microservice-b directory:
    cd microservice-b
  2. Install dependencies:
    npm install
  3. Create a .env file (optional) with:
    RABBIT_URL=amqp://localhost
    QUEUE=messageQueue
    
  4. Start the service:
    npm start

Testing

Microservice A Tests

From the microservice-a directory, run:

npm test

This executes unit tests for the /send endpoint.

Microservice B Tests

From the microservice-b directory, run:

npm test

This runs tests to verify that incoming messages are correctly processed.

Challenges and Resolutions

  • Reliable Asynchronous Messaging:
    By ensuring persistent messaging and proper acknowledgment in RabbitMQ, the system can reliably process messages even under load.

  • Decoupling Services:
    Using RabbitMQ allows each service to operate independently, easing scalability and maintenance.

  • Testing Asynchronous Code:
    We mock the RabbitMQ connection and channels in tests to simulate message delivery without a live broker.

Conclusion

Any fool can write code that a computer can understand 🤖. Good programmers write code that humans can understand💡

Happy coding🚀

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published