Skip to content

fragonib/quarkus-kata

Repository files navigation

Solar monitor kata

An exercise to practice real problem-solving with Quarkus framework

TO DO

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:

  1. Receives incoming readings' data via HTTP PUT.

  2. Computes average power values from energy readings.

  3. Stores the datapoints (records with at least a timestamp, energy and power values).

  4. 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).

Technologies used

  • 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)

Focused on

  • Design patterns

  • SOLID

  • Event oriented design

Requirements

  1. At least JVM 11 to build and run the project

  2. GraalVM to build native app

Running

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

Containers

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 mongodb://mongodb:27017 hostname, so in local you need manually resolve that IP

/etc/hosts
127.0.0.1       mongodb

What could be improved?

  • 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

KNOWN errors

Currently, some tests aren’t idempotent because they don’t clean app state before start

About

A Kata using Vert.x and EventBus

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published