DPIclimate / broker

3 stars 3 forks source link

Add message received time to the get messages REST API response #82

Closed dajtxx closed 3 months ago

dajtxx commented 3 months ago

It would be useful to have the api/messages response to include the message received time to allow analysis of delivery delays.

A new parameter must be added to the REST API and DAO functions, boolean include_received_at.

Given the standard message format already contains the timestamp, this issue can be addressed by adding a new received_at field to the standard message format. For now this field is added by the DAO in response to this call - no database updates are required.

So the response to these API functions is a list of JSON messages in IoTa internal format. If only timestamps are required, or only timestamps and received at times, the rest of the standard message is dropped.

only_timestamp = false, include_received_at = false:

[
  {
    "l_uid": 1,
    "p_uid": 1,
    "timestamp": "2024-06-20T05:52:57.332116058Z",
    "timeseries": [
      {
        "name": "airTemperature",
        "value": 15.4
      }
   ],
    "broker_correlation_id": "06082d36-a041-4121-8636-3d5e90a2cdd4"
  }
]

only_timestamp = true, include_received_at = true:

[
  {
    "timestamp": "2024-06-20T05:52:57.332116058Z",
    "received_at": "2024-06-20T05:52:57.62Z"
  }
]

only_timestamp = false, include_received_at = true:

[
  {
    "l_uid": 1,
    "p_uid": 1,
    "timestamp": "2024-06-20T05:52:57.332116058Z",
    "timeseries": [
      {
        "name": "airTemperature",
        "value": 15.4
      }
   ],
    "broker_correlation_id": "06082d36-a041-4121-8636-3d5e90a2cdd4",
    "received_at": "2024-06-20T05:52:57.62Z"
  }
]
dajtxx commented 3 months ago

Implemented with commit 8fe253b.