This guide will walk you through the installation process of a NestJS project integrated with RabbitMQ.
Before you begin, ensure that you have the following prerequisites installed on your machine:
- Node.js (version 14 or above)
- npm (Node Package Manager) or yarn
-
Open your terminal or command prompt.
-
Navigate to the directory where you want to clone the repository.
-
Run the following command to clone the repository:
git clone https://github.com/mohanadft/Messanger.git
-
Once the repository is cloned, navigate into the project directory:
cd Messanger
-
Run the following command to install the project dependencies:
yarn install
This command will download and install all the required dependencies specified in the
package.jsonfile.
Certainly! Here's an updated section for using Docker Compose with RabbitMQ in your NestJS project:
If you prefer to run RabbitMQ using Docker Compose, you can follow these steps:
Before proceeding, ensure that you have Docker and Docker Compose installed on your machine.
-
Create a
docker-compose.ymlfile in the root directory of your project. -
Open the
docker-compose.ymlfile and add the following configuration:version: '3' services: rabbitmq: image: rabbitmq:3-management container_name: rabbitmq hostname: rabbitmq volumes: - /var/lib/rabbitmq ports: - '5672:5672' - '15672:15672' env_file: - ./.env
This configuration uses the
rabbitmq:3.9-managementimage, which includes both RabbitMQ and the management UI. It exposes ports5672for RabbitMQ and15672for the management UI.Make sure to set the
RABBITMQ_DEFAULT_USERandRABBITMQ_DEFAULT_PASSenvironment variables to the desired username and password for your RabbitMQ instance.
-
Open your terminal or command prompt.
-
Navigate to the root directory of your project (where the
docker-compose.ymlfile is located). -
Run the following command to start the containers:
docker compose up
This command will download the RabbitMQ Docker image (if not already available) and start the RabbitMQ container.
You should see the RabbitMQ logs in the console, indicating that the RabbitMQ server has started and the management UI is accessible at http://localhost:15672.
To stop and remove the RabbitMQ containers, you can use the following command:
docker compose downThis command will stop the containers and remove them, freeing up the resources.
Make sure to set the URL to amqp://localhost:5672 to match the Docker container's configuration.
-
Start the NestJS Application:
-
In your terminal, run the following command to start the NestJS application:
yarn start:server
-
Run the auth service:
cd server yarn run start:dev auth -
The application will start running, and you should see the console output indicating that the server has started.
-
-
Verify the Application:
- Open your browser and navigate to http://localhost:3000 (or the specified port).
- If the application loads successfully, you have set up the NestJS project with RabbitMQ correctly.
Congratulations! You have successfully installed and configured a NestJS project integrated with RabbitMQ. You can now proceed with using RabbitMQ for message processing in your NestJS application.
If you encounter any issues or have further questions, please refer to the troubleshooting section or reach out for support.
In this installation guide, you learned how to set up a NestJS project with RabbitMQ. You cloned the
repository, installed the dependencies, configured RabbitMQ, and ran the application. Feel free to explore the project further and start integrating RabbitMQ into your NestJS application for messaging functionality.
If you have any feedback or suggestions for improvement, please don't hesitate to reach out or contribute to the project.
Happy coding!