An exercise to practice real problem-solving with Quarkus framework
You’re working on a company that manages solar energy production plants. There are several devices that report energy readings from building power lines, and we need to incorporate the data they provide to the system.
The devices send an energy reading (a value that always grows) periodically:
{
"device": String,
"timestamp": Timestamp,
"energy": Number
}
We need to create a small service that does the following:
-
Receives incoming readings' data via HTTP PUT.
-
Computes average power values from energy readings.
-
Stores the datapoints (records with at least a timestamp, energy and power values).
-
Has an endpoint to get a list of data points from the service, filtered by timestamps and the data source (
GET /api/v1/data-points?start=xxx&end=xxx&device-id=xxx
for example, you can use anything you want).
-
Gradle (for building project)
-
Kotlin (for production code)
-
Hexagonal architecture
-
Reactive programming model (with non-blocking I/O)
-
Mongo for Sensor Readings repository (decoupled thanks to using hexagonal architecture)
To build the entire app with:
./gradlew clean build
To build the entire app but without running any tests:
./gradlew clean build -x test
To run all tests, external dependencies (ie: DB engines) are mocked:
./gradlew test
To run the entire app (in localhost) in PROD mode:
java -jar build/quarkus-app/quarkus-run.jar
Note
|
Requires a running mongo database cluster. You can play with local one: docker run -ti --rm -p 27017:27017 mongo |
Once up & running you can check and interact with the REST API using swagger UI
To run application in DEV mode:
./gradlew quarkusDev
In this mode you can interact with app dev insights
You can build the container image by (make sure you build the app first ./gradlew clean build
):
docker build -f src/main/docker/Dockerfile.jvm -t quarkus/solar-monitor-jvm .
A running mongo database cluster is needed, but you can play with local one:
docker run -ti --rm -p 27017:27017 mongo
Then you can run the container local using:
docker run -i --net="host" --rm -p 8080:8080 quarkus/solar-monitor-jvm
Note
|
Image use /etc/hosts
127.0.0.1 mongodb |
-
Add support for native image
-
Authorization should be used on REST endpoints to guarantee energy reports are coming from trusted sensors
-
Add trace instrumentation (ie.: OpenTracing) to trace complete journey of a message
-
Add business metrics (ie.: with Micrometer)
-
Use of NoSQLUnit like framework to drive DB related Integration Tests