This project emulates a distributed web application for reporting measurements of heat monitoring devices.
The figure below illustrates the architecture of the project.
To run the project locally you need to have Docker and Docker Compose installed. After cloning this repository, follow the steps below.
Open a terminal and navigate to the project's root directory. There you will find two directories: device/
and server/
.
.
├── device
├── README.md
└── server
First, go to the server/
directory. There you will need to create a .env
file with the content of the .env.example
file.
Second, yet in the server/
directory, you will find a credentials/
subdirectory.
.
├── device
├── README.md
└── server
├── credentials
│ └── example-credentials.json
...
There you will need to create a credentials.json
file with a valid service account key, as illustrated in the example-credentials.json
file.
After that, we are good. Go back to the server
directory and run the following command:
make build
It will:
- create the network that will connect the device's and server's containers;
- create the database volume;
- and build the server's containers.
The server's containers have:
- a Django application that exposes a REST API and an admin panel through port 8000 of the host machine (http://localhost:8000);
- a PostgreSQL database server that will persist the data;
- a Redis server that will be used as a message broker for the Celery task queue;
- and a Celery worker responsible for asynchronously processing the requests to generate the reports based on the data sent by the device emulator.
To start the containers, run:
make up
If you want to watch the logs of the server's containers, run:
make logs
For convenience, you can run the following command to create an admin user with the credentials admin:admin
:
make create-admin
That will be particularly useful for logging in on the admin panel of the Django application to check if the data is being stored correctly.
Now, (optionally open another terminal,) navigate to the device/
directory, and run:
make up
It will create the following containers:
- the RabbitMQ server that will be used as a message broker to emulate the communication gateway between the device and the server;
- a process that will emulate the communication gateway, receiving the measurements from the RabbitMQ server and sending them to the server's REST API;
- a process that will emulate the device's sensor, sending measurements to the RabbitMQ server. This process will send a measurement within an interval of 1 to 5 seconds. There are 10 measurement samples. After sending all of them, it will start over from the first one in a loop.
Again, if you want to watch the logs of the device emulator's containers, run:
make logs
To stop the containers, run:
make down
To require a report, with the application running, access the endpoint http://localhost:8000/api/measurements/report/
and press the button "Generate report".
Follow the instructions on the screen to download the report.
- The device emulator sends a measurement to the RabbitMQ server;
- The communication gateway receives the measurement from the RabbitMQ server;
- The communication gateway sends the measurement to the server's API;
- The server's API stores the measurement in the database;
- The server's API sends an HTTP response to the communication gateway.
- The user requires a report through the server's REST API;
- The server's API sends a message to the Redis broker;
- The server's API sends an HTTP response to the user;
- The Celery worker receives the message from the Redis broker;
- The Celery worker queries the database for the measurements;
- The Celery worker generates the report and uploads it to the bucket.
This project was developed by Lucas Cavalcante.