Simple HTTP web service which processes telemetries from MQTT server
mqtt.hsl.fi written in Go
The service stores the telemetries from the MQTT server and enables REST endpoints to browse through them via pagination.
It also enables endpoint to get the list of the nearest bus telemetries for given position.
See how to run the service.
Prior to building the service I had made the following assumptions.
- Web service should store all the telemetries from the subscription
- User is able to provide current location in form of latitude and longitude
- Web service would be used only in the same timezone
- Go
- GORM - ORM to handle database tables in Go (Automigrations enabled)
- Docker
- Postgres
The web service can be started as a docker container specified by docker-compose.yml file
To run the web service via the docker-compose you are going to need .env file with the following variables.
DB_HOST
- host address for the database
Note: has to be name of the database service in docker-compose if docker is usedDB_PORT
- port the database is going to run onDB_USER
- database userDB_PASSWORD
- password for the userDB_NAME
- name of the database
HTTP_URL
- host address for the http server
Note: has to be "0.0.0.0" for the docker environment runtime. Can be changed if docker not usedHTTP_PORT
- port that the http server will be exposed on
# database connection
DB_HOST=telemetry-database
DB_PORT=5432
DB_USER=admin
DB_PASSWORD=strongPw
DB_NAME=telemetries
# HTTP server
HTTP_URL=0.0.0.0
HTTP_PORT=3000
To build the container run following command: docker-compose up -d --build
GET <host>:<port>/api/v1/telemetries
GET <host>:<port>/api/v1/telemetries?pageSize=20&page=1
Name | Required | Default value | Description |
---|---|---|---|
pageSize | false | 20 | number of telemetries per page |
page | false | 1 | number of the current page |
GET <host>:<port>/api/v1/buses/nearest?lat=60.205183&lon=25.145534
Name | Required | Default value | Description |
---|---|---|---|
lat | true | None | latitude location of the user |
lon | false | None | longitude location of the user |
I have also added a new unit tests to test the most crutial parts of the application - calculating the distance and parsers.
The tests run automatically upon Dockefile build.
You can also run them via terminal by this command.
go test ./..a