Position forwarding Kafka

Khalil HADDED2 years ago

I am using kafka to forward positions.

From Kafka topic i get this data:

{
  "position": {
    "id": 0,
    "attributes": {
      "batteryLevel": 55,
      "steps": 0,
      "distance": 0.0,
      "totalDistance": 5.50504519E7,
      "motion": false
    },
    "deviceId": 2,
    "protocol": "watch",
    "serverTime": "2023-08-13T19:48:19.792+00:00",
    "deviceTime": "2023-08-13T19:48:19.792+00:00",
    "fixTime": "2023-08-13T19:47:00.000+00:00",
    "outdated": true,
    "valid": true,
    "latitude": 36.8135368,
    "longitude": 10.1710941,
    "altitude": 0.0,
    "speed": 0.0,
    "course": 0.0,
    "address": null,
    "accuracy": 3243.0,
    "network": null,
    "geofenceIds": null
  },
  "device": {
    "id": 2,
    "attributes": {

    },
    "groupId": 0,
    "calendarId": 0,
    "name": "watch",
    "uniqueId": "9705141740",
    "status": "online",
    "lastUpdate": "2023-08-13T19:48:19.792+00:00",
    "positionId": 1678,
    "phone": null,
    "model": null,
    "contact": null,
    "category": null,
    "disabled": false,
    "expirationTime": null
  }
}

position.id : 0
device.positionId : 1678

But when i fetch device from Api I get this:

{
        "id": 2,
        "attributes": {},
        "groupId": 0,
        "calendarId": 0,
        "name": "watch",
        "uniqueId": "9705141740",
        "status": "online",
        "lastUpdate": "2023-08-13T19:48:19.792+00:00",
        "positionId": 1682,
        "phone": null,
        "model": null,
        "contact": null,
        "category": null,
        "disabled": false,
        "expirationTime": null
    }

device.positionId : 1682

So, device.positionId it's not updated in kafka data. and there is no position.id

And I need to save the last position id of the device in my server. How can i achieve that ?

Thank you.

Anton Tananaev2 years ago

Forwarding happens before the data is inserted in the database, so there's no position id.

Khalil HADDED2 years ago

So I need to retrieve device's positionId from Api when receiving kafka data.

Anton Tananaev2 years ago

Why do you need it?

Khalil HADDED2 years ago

I am in the process of developing a middleware server to serve as an intermediary between my client application and the Traccar server. Specifically, this middleware will consume positions from Traccar, update the last known position of the device, and subsequently distribute these updates to the client application. I believe it would be prudent to save the last known position's ID (corresponding to Traccar's position ID) of the device. This will facilitate error handling in potential future scenarios.