Skip to content

ahmadalsharef994/TypeScript_Microservices_RabbitMQ_Publisher_Consumer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

TypeScript Microservices — RabbitMQ Publisher/Consumer

TypeScript Node.js RabbitMQ Microservices License

A clean TypeScript microservices example demonstrating asynchronous communication between services via RabbitMQ — publisher sends messages to a queue, consumer processes them independently. A practical reference for decoupled service-to-service communication.


🏗️ Architecture

flowchart LR
    subgraph Publisher Service
        P["📤 Publisher\n(TypeScript)"]
        P -->|"channel.publish()"| Q
    end

    subgraph RabbitMQ
        Q["📨 Queue\n(durable)"]
    end

    subgraph Consumer Service
        Q -->|"channel.consume()"| C["📥 Consumer\n(TypeScript)"]
        C --> ACK["✅ ack / ❌ nack"]
    end

    style Q fill:#FF6600,color:#fff
Loading

Message Flow

sequenceDiagram
    participant P as Publisher Service
    participant RMQ as RabbitMQ
    participant C as Consumer Service

    P->>RMQ: connect + assertQueue("tasks")
    P->>RMQ: publish(message)
    RMQ-->>C: deliver message
    C->>C: process message
    C->>RMQ: ack (success) or nack (retry)
Loading

🚀 Quick Start

Prerequisites: Node.js 18+, RabbitMQ running locally

git clone https://github.com/ahmadalsharef994/TypeScript_Microservices_RabbitMQ_Publisher_Consumer.git
cd TypeScript_Microservices_RabbitMQ_Publisher_Consumer

Start RabbitMQ

docker run -d --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:management
# Management UI: http://localhost:15672  (guest/guest)

Run Publisher

cd Publisher_Service
npm install
npm run start

Run Consumer (new terminal)

cd Consumer_Service
npm install
npm run start

📁 Project Structure

├── Publisher_Service/
│   ├── src/
│   │   └── publisher.ts    # Connects to RabbitMQ, sends messages
│   ├── package.json
│   └── tsconfig.json
└── Consumer_Service/
    ├── src/
    │   └── consumer.ts     # Connects to RabbitMQ, processes messages
    ├── package.json
    └── tsconfig.json

💡 Key Concepts Demonstrated

Concept Where
Queue declaration with durable: true publisher.ts
Message persistence (persistent: true) publisher.ts
Manual ack/nack for reliability consumer.ts
Connection retry logic both services
TypeScript strong typing on messages both services

🤝 Contributing

PRs welcome. Please fork, branch, and open a pull request.

📄 License

MIT

About

A TypeScript-based microservice pattern implementation showing RabbitMQ message publishing and consumption for asynchronous communication.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors