Skip to content

llinq/node-rabbitmq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node Pub/Sub

Study project focused on Node.js with TypeScript and event-driven architecture using RabbitMQ.

Features

  • Class-Based Architecture: Robust implementation of abstract Publishers and Consumers.
  • RabbitMQ: Full integration with exchanges, queues, and dead letter queues.
  • REST API: Express server to create orders via HTTP.
  • Automation Scripts: Tools for load testing and manual pub/sub.
  • Tutorials: Practical examples

Prerequisites

  1. Node.js
  2. Docker & Docker Compose (to run RabbitMQ)

Installation

  1. Install dependencies:

    npm install
  2. Start RabbitMQ:

    docker-compose up -d

How to Use

1. Hello World

Quick test to verify RabbitMQ connection.

  • Receive messages:
    npm run hello:receive
  • Send messages:
    npm run hello:send

2. Work Queues

Distribute time-consuming tasks among multiple workers.

  • Start Worker:
    npm run work:worker
  • Send New Task:
    npm run work:new_task -- "My Task..."
  • Send Multiple Tasks:
    npm run work:send_tasks

3. Publish/Subscribe

Broadcast messages to multiple consumers (logging).

  • Receive Logs:
    npm run log:receive
  • Emit Log:
    npm run log:emit -- "Log info..."

4. Routing

Subscribe only to a subset of messages (e.g. only critical errors).

  • Receive Logs (info, warning):
    npm run log:receive:direct -- info warning
  • Emit Log (error):
    npm run log:emit:direct -- error "Run. Run. Or it will explode."

5. Topics

Receive messages based on a pattern (topics).

  • Receive (all logs):
    npm run log:receive:topic -- "#"
  • Receive (kernel logs):
    npm run log:receive:topic -- "kern.*"
  • Emit Log:
    npm run log:emit:topic -- "kern.critical" "A critical kernel error"

6. RPC (Remote Procedure Call)

Request/reply pattern for remote procedure calls.

  • Start Server:
    npm run rpc:server
  • Send Request:
    npm run rpc:client -- <number>
    Example: npm run rpc:client -- 30

7. Order System

Complete simulation of an order creation flow.

A. Run the Consumer

Starts the service listening to the order.created queue.

npm run order:consume

B. Publish an Order (Manual)

Sends a single order event to the queue.

npm run order:publish

C. Load Test (Bulk)

Publishes multiple orders at once to test processing.

# Publishes 1000 orders (default)
npm run order:bulk

8. REST API

Starts the Express server to receive orders via HTTP.

  1. Start the API:

    npm run api
  2. Create an order (curl example):

    curl -X POST http://localhost:3000/api/orders \
         -H "Content-Type: application/json" \
         -d '{"orderId": "123", "total": 99.90, "userId": "user_01"}'

Monitoring

Access the RabbitMQ management dashboard:

Project Structure

  • src/api: Express server.
  • src/consumer: Consumer logic (Base + Implementations).
  • src/producer: Publisher logic (Base + Implementations).
  • src/events: Event type definitions and interfaces.
  • src/infra: RabbitMQ configuration and client.
  • src/scripts: Utility scripts for manual testing.
  • src/tutorials: Introductory examples.

Project for study purposes.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors