deviceservice's People
deviceservice's Issues
Add device
-
provide endpoint
POST /devices
that accepts payload{ Name: string, Interval: int, Value: float }
-
Interval > 0
-
Name cannot be empty
-
endpoint returns Device object
{
Id: int,
Name: string,
Interval: int,
Value: float
}
- example request:
http :8000/devices name="test name" interval:=-1
- example request2:
http :8000/devices < device1.json
where
device1.json
is a file that looks like:{"name": "test name", "interval": -1 }
Implement measurements persistence
Create new implementation of MeasurementsWriter that saves measurements in InfluxDB.
- for every value received, write it to influxDB as influx's value, deviceId as Influx's tag and with timestamp =
now()
and precision set to second. values should be stored in influx's measurement calleddeviceValues
, database calledmydb
- in case write fails just log it
- InfluxDB address should be read from environment variable. If InfluxDB is not reachable during
deviceService
start it should panic
Example test InfluxDB query: SELECT * FROM deviceValues group by deviceId
Get device by Id
- implement endpoint
GET /devices/:id
that returns device object - it should return 400 if
id
was not a number - it should return 404 if device was not found
- it should return 500 in case there was an error in DAO
Persist devices in MongoDB
- on
POST /devices
store device in MongoDB - on
GET /devices/:id
read device from db - on
GET /devices
read all devices from db
- use MongoDB version 3.6 or higher (the newest is fine as well)
- use official mongodb golang driver (https://github.com/mongodb/mongo-go-driver)
- initialize mongoDB connection in
main.go
GET all devices
- implement endpoint
GET /devices
that returns list of all devices - endpoint has to accept size and limit HTTP query parameters:
limit
- limits length of returned. Default limit = 100. If limit == 0, ignore page (even if provided) and return all devicespage
- tells which page should be returned. Page starts from 0. Default page = 0.
- it should return 400 if
page
orlimit
are not integer or less than zero - it should return empty json array (
[]
) when there were no devices - it should return 500 in case there was an error in DAO
Example request: http :8000/devices page==2 limit==4
Communicate Ticker and Writer using RabbitMQ
Ticker service should push new dataPoints/measurements on RabbitMQ topic (instead of golang channel).
- topic name:
measurements
- routing key should be set to device id
Writer service should accept measurements on the RabbitMQ topic. It should listen to measurements from all devices.
Implement TickerService
- Ticker service, when started, reads all devices from. For every device:
- create new
time.Ticker
that ticks in intervals read from device - on tick, send new measurement to
chan<- Measurement
, setting value and id read from device
- create new
- Add endpoint
POST /start
that starts the Ticker
- Implement MeasurementsWriter
- MeasurementsWriter, when started, waits for measurements from
<-chan Measurement
- on new measurement it just prints it out to the console
type Measurement struct {
Id int
Value float64
}
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.