Sensor service or microservice B is service that consume and process the data from microservices A, also in this service has REST API sensor data, authentication & authorization check. please be make sure the Sensor streaming(A) running first.
This service made to containerize the allcare core service make a clear separation of concern within the architecture with Uncle Bob Clean Architecture interpretation.
Based on Uncle Bob, there are 4 layers:
- Entity
- Use Cases
- Interface Adapters
- Frameworks and Drivers.
In this repository, we also using 4 layers (with modification) like this:
- Entity.
- Use Cases (Implementation).
- Interface Adapters. Will be splitted into two:
- Repository Interface. Bridging repository implementation and use cases layer.
- Use Case Interface. Bridging handler and use cases layer.
- Driver Layer
- Handler
- Repository implementation
- Google Golang Format used for code style formatting
- Sonarlint used to check code cleanness and help prevent NPE
- Resource Naming Guide used to make a clear resource naming
- Setup skeleton of the microservices (including: main.go, cmd, server, migrations, config, platform. handler)
- Defining the
entity - Defining
usecase(interface & implementation) in foldermodule/sensor/useaces. We're gonna focus in this folder since the business logic will be written here. - When the usecase need to communicate to the external agency (Database) then write it to the
repository interface - After the usecase layer was done, now time to write
repository implementation - Put it up together + register to the module/sensor/service.go and init module dependency in server.go
Please setup the backend environment in this file app.yaml.
app:
port: 8080
name: sensor_streaming
secret_key: "oksecret!1"
mysql:
host: host.docker.internal
port: 3306
driver_name: mysql
username: cabin
password: cabinpw
charset: utf8
db_name: sensor
max_open_connection: 5
max_idle_connection: 2
max_lifetime_connection: 60s
db_migrate: false
kafka:
host: host.docker.internal
port: 9092
mqtt:
host: host.docker.internal
port: 1883
Please setup the docker environment in this file .env.docker.
MYSQL_ROOT_PASSWORD=rootpw
MYSQL_DATABASE=sensor
MYSQL_USER=cabin
MYSQL_PASSWORD=cabinpw
dbconfig.yml config file should specify like this,
development:
dialect: mysql
datasource: dbname=postgres port=5432 user=routesroot sslmode=disable
dir: internal/platform/storage/migration
command migration,
$ sql-migrate --help
usage: sql-migrate [--version] [--help] <command> [<args>]
Available commands are:
down Undo a database migration
new Create a new migration
redo Reapply the last migration
status Show migration status
up Migrates the database to the most recent version available
last, set the db_migrate flag in app.yaml of the migration it will be execute when app is starting
db_migrate: true
open terminal cd to this project's root folder and run script below
swag init
docker-compose --env-file .docker.env up