A comprehensive demonstration of message queuing with RabbitMQ and Apache Kafka using Node.js, featuring Docker containerization and REST API endpoints.
- RabbitMQ Integration: Producer and consumer services with queue management
- Apache Kafka Integration: Topic-based messaging with consumer groups
- REST API: HTTP endpoints for message production
- Docker Compose: Full-stack containerized environment
- Health Checks: Service health monitoring
- Example Scripts: Ready-to-use demonstration scripts
- Load Testing: Performance testing capabilities
- Docker and Docker Compose
- Node.js 18+ (for local development)
- Git
-
Clone the repository:
git clone https://github.com/jmrashed/rabbitmq-kafka-node-demo.git cd rabbitmq-kafka-node-demo
-
Start all services:
docker-compose up -d
-
Check service health:
docker-compose ps
-
Install dependencies:
npm install
-
Start infrastructure services:
docker-compose up -d rabbitmq kafka zookeeper
-
Run the application:
npm run dev
Service | Port | Management UI |
---|---|---|
Node.js App | 3000 | - |
RabbitMQ | 5672 | http://localhost:15672 |
RabbitMQ Management | 15672 | guest/guest |
Kafka | 9092 | - |
Zookeeper | 2181 | - |
POST /produce
curl -X POST http://localhost:3000/produce \
-H "Content-Type: application/json" \
-d '{
"type": "rabbitmq",
"queue": "task_queue",
"message": "Hello RabbitMQ!"
}'
curl -X POST http://localhost:3000/produce \
-H "Content-Type: application/json" \
-d '{
"type": "kafka",
"topic": "task_logs",
"message": "Hello Kafka!",
"key": "log-key-1"
}'
Run the provided example scripts to test the system:
# Send a RabbitMQ message
node examples/send-rabbitmq.js
# Send a Kafka message
node examples/send-kafka.js
# Run load test (default: 10 messages each)
node examples/load-test.js
# Run load test with custom count
node examples/load-test.js 50
Run the test suite:
npm test
- URL: http://localhost:15672
- Username:
guest
- Password:
guest
# View all logs
npm run docker:logs
# View specific service logs
docker-compose logs -f app
docker-compose logs -f rabbitmq
docker-compose logs -f kafka
βββ config/ # Configuration files
β βββ kafka.js # Kafka configuration
β βββ logger.js # Winston logger setup
β βββ rabbitmq.js # RabbitMQ configuration
βββ services/ # Core services
β βββ consumer/ # Consumer implementations
β βββ producer/ # Producer implementations
β βββ consumer-service.js
β βββ producer-service.js
βββ examples/ # Example scripts
β βββ send-rabbitmq.js # RabbitMQ example
β βββ send-kafka.js # Kafka example
β βββ load-test.js # Load testing
βββ test/ # Test files
βββ docker-compose.yml # Docker services
βββ Dockerfile # App container
βββ README.md
npm run docker:up
npm run dev
npm run docker:down
npm run docker:logs
-
Build production image:
docker build -t rabbitmq-kafka-app .
-
Deploy with production compose:
docker-compose -f docker-compose.yml up -d
- Fork the repository
- Create a feature branch:
git checkout -b feature/new-feature
- Commit changes:
git commit -am 'Add new feature'
- Push to branch:
git push origin feature/new-feature
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
Services not starting: Check Docker daemon is running
docker --version
docker-compose --version
Port conflicts: Ensure ports 3000, 5672, 9092, 15672, 2181 are available
netstat -an | findstr "3000\|5672\|9092\|15672\|2181"
Connection refused: Wait for services to be healthy
docker-compose ps
All services include health checks. Wait for all services to show "healthy" status before testing.
- RabbitMQ: Optimized for reliable message delivery
- Kafka: Optimized for high-throughput streaming
- Both support clustering for production scalability
Made with β€οΈ by jmrashed