JSON REST API and Open Weather Map Microservices

JSON REST API

JSON REST API is a system container that provides a restful endpoint and allows to transform the data generated by a microservice.

The config for the container should look in the following way:

{\"buffersize\":3,\"contentdataencoding\":\"utf8\",\"contextdataencoding\":\"utf8\",\"outputfields\":{\"publisher\":\"source\",\"contentdata\":\"temperature\",\"timestamp\":\"time\"}}

Which translates to the following YAML microservice file :

apiVersion: iofog.org/v1
kind: Microservice
metadata:
  name: json-rest-api
spec:
  agent:
    name: local-agent
    ...
  images:
    catalogId: 7
  config:
    buffersize: 3
    contentdataencoding: utf8
    contextdataencoding: utf8
    outputfields:
      publisher: source
      contentdata: temperature
      timestamp: time
  ports: []
  ...
  application: my-application

Config explanation:

{"buffersize":3} - this instructs the microservice to show last 3 messages

"publisher" - the uuid of ms sent messages

"contentdata" - message format

E.g. if we route the microservice with Open Weather Map microservice, this will allow to access the weather data in a browser or in any other application or any device cloud.

Open Weather Map

Open Weather Map is a system container that retrieves the data from https://openweathermap.org/.

The config for the container should look in the following way:

{\"citycode\":\"5391997\",\"apikey\":\"6141811a6136148a00133488eadff0fb\",\"frequency\":1000}

Which translates to the following YAML microservice file :

apiVersion: iofog.org/v1
kind: Microservice
metadata:
  name: open-weather-map
spec:
  agent:
    name: local-agent
    ...
  images:
    catalogId: 8
  config:
    citycode: 5391997
    apikey: 6141811a6136148a00133488eadff0fb
    frequency: 1000
  ports: []
  ...
  application: my-application

Config explanation:

"citycode" - the code of the city

"apikey" - the api key of open weather map

"frequency" - the frequency of message sending in millis

Launching the Container

  • The JSON REST API images will always be available on ioFog Controllers using the catalog item ID 7.
  • The Open Weather Map images will always be available on ioFog Controllers using the catalog item ID 8.

Please refer to the catalog overview if you don't know yet how to deploy microservices using catalog items.

Request

$ curl localhost:5555

Response

[
  {
    "source": "CmdxYrfZmPRLTH7rXMwKpW92zRHtggxw",
    "temperature": "{\"coord\":{\"lon\":-122.45,\"lat\":37.77},\"weather\":[{\"id\":801,\"main\":\"Clouds\",\"description\":\"few clouds\",\"icon\":\"02n\"}],\"base\":\"stations\",\"main\":{\"temp\":279.46,\"pressure\":1028,\"humidity\":65,\"temp_min\":276.45,\"temp_max\":282.55},\"visibility\":16093,\"wind\":{\"speed\":1.5,\"deg\":320},\"clouds\":{\"all\":20},\"dt\":1548161760,\"sys\":{\"type\":1,\"id\":5817,\"message\":0.0037,\"country\":\"US\",\"sunrise\":1548170436,\"sunset\":1548206570},\"id\":5391997,\"name\":\"San Francisco County\",\"cod\":200}",
    "time": 1548163407511
  },
  {
    "source": "CmdxYrfZmPRLTH7rXMwKpW92zRHtggxw",
    "temperature": "{\"coord\":{\"lon\":-122.45,\"lat\":37.77},\"weather\":[{\"id\":801,\"main\":\"Clouds\",\"description\":\"few clouds\",\"icon\":\"02n\"}],\"base\":\"stations\",\"main\":{\"temp\":279.46,\"pressure\":1028,\"humidity\":65,\"temp_min\":276.45,\"temp_max\":282.55},\"visibility\":16093,\"wind\":{\"speed\":1.5,\"deg\":320},\"clouds\":{\"all\":20},\"dt\":1548161760,\"sys\":{\"type\":1,\"id\":5817,\"message\":0.0037,\"country\":\"US\",\"sunrise\":1548170436,\"sunset\":1548206570},\"id\":5391997,\"name\":\"San Francisco County\",\"cod\":200}",
    "time": 1548163408502
  },
  {
    "source": "CmdxYrfZmPRLTH7rXMwKpW92zRHtggxw",
    "temperature": "{\"coord\":{\"lon\":-122.45,\"lat\":37.77},\"weather\":[{\"id\":801,\"main\":\"Clouds\",\"description\":\"few clouds\",\"icon\":\"02n\"}],\"base\":\"stations\",\"main\":{\"temp\":279.46,\"pressure\":1028,\"humidity\":65,\"temp_min\":276.45,\"temp_max\":282.55},\"visibility\":16093,\"wind\":{\"speed\":1.5,\"deg\":320},\"clouds\":{\"all\":20},\"dt\":1548161760,\"sys\":{\"type\":1,\"id\":5817,\"message\":0.0037,\"country\":\"US\",\"sunrise\":1548170436,\"sunset\":1548206570},\"id\":5391997,\"name\":\"San Francisco County\",\"cod\":200}",
    "time": 1548163409419
  }
]