Welcome to the RabbitMQ Demo project! This tutorial demonstrates a simple publisher-consumer pattern using RabbitMQ as a message broker. We'll use Node.js and Docker Compose to set up the project easily and manage dependencies.
RabbitMQ: Acts as the message broker managing message queues and message delivery.
Exchange: (default) Routes messages to appropriate queues based on routing rules.
Queues:
- messages: Stores messages sent by the publisher.
- logs: Receives messages consumed and logged by the consumer.
Publisher:
- Generates random numbers as messages.
- Sends messages to the RabbitMQ server, which routes them to the messages queue.
Consumer:
- Subscribes to the messages queue.
- Receives messages from RabbitMQ.
- Logs the received messages to the console or a log file.
- Uses RabbitMQ for message queuing.
- Implements a publisher sending random numbers as messages.
- Implements a consumer receiving and logging messages.
- Docker Compose simplifies running the services.
Make sure you have the following installed on your system:
- Docker: Follow the installation guide here.
- Docker Compose: Follow the installation guide here.
- Node.js and npm: Install from nodejs.org.
rabbitmq-demo/
├── publisher/
│ └── index.js
├── publisher-consumer/
│ └── index.js
└── consumer/
└── index.js
├── docker-compose.yml
Clone or download the RabbitMQ Demo repository:
git clone <repository-url>
cd rabbitmq-demoBuild the Docker images defined in docker-compose.yml:
docker-compose buildStart the services using Docker Compose in detached mode:
docker-compose up -dThis command starts RabbitMQ along with the publisher and consumer services.
Open your web browser and go to http://localhost:15672. You can use the default credentials:
- Username:
guest - Password:
guest
The Docker Compose file defines three services:
- RabbitMQ: Message broker used for queuing messages.
- publisher: Sends random numbers as messages to RabbitMQ.
- consumer: Receives and logs messages from RabbitMQ.
This file contains the logic for the publisher, which generates random numbers and sends them to RabbitMQ using the amqplib library.
This file contains the logic for the consumer, which listens for messages from RabbitMQ and logs them to the console.
Feel free to customize the project:
- Modify the message format in
publisher/index.js,publisher-consumer/index.js, andconsumer/index.js. - Add error handling and logging functionalities as needed.
- Explore advanced RabbitMQ features like exchanges and routing keys.
This project is licensed under the MIT License. See the LICENSE file for details.
