Study project focused on Node.js with TypeScript and event-driven architecture using RabbitMQ.
- 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
- Node.js
- Docker & Docker Compose (to run RabbitMQ)
-
Install dependencies:
npm install
-
Start RabbitMQ:
docker-compose up -d
Quick test to verify RabbitMQ connection.
- Receive messages:
npm run hello:receive
- Send messages:
npm run hello:send
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
Broadcast messages to multiple consumers (logging).
- Receive Logs:
npm run log:receive
- Emit Log:
npm run log:emit -- "Log info..."
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."
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"
Request/reply pattern for remote procedure calls.
- Start Server:
npm run rpc:server
- Send Request:
Example:
npm run rpc:client -- <number>
npm run rpc:client -- 30
Complete simulation of an order creation flow.
Starts the service listening to the order.created queue.
npm run order:consumeSends a single order event to the queue.
npm run order:publishPublishes multiple orders at once to test processing.
# Publishes 1000 orders (default)
npm run order:bulkStarts the Express server to receive orders via HTTP.
-
Start the API:
npm run api
-
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"}'
Access the RabbitMQ management dashboard:
- URL: http://localhost:15672
- User:
guest - Password:
guest
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.