Search code examples
azureazure-functionsazure-iot-hub

How to process current and previous IoT Hub event from an azure function?


I have a simple scenario where I want to take the diff between current value of a parameter and previous value from IoT hub telemetry messages and attach this result and send to Time Series Insights environment (via an event hub if required so).

How can I achieve this? I am studying about Azure functions but not able to figure out how to exactly go about it.

The minimum timestamp difference between messages is 1 second and only edge devices (at max perhaps 3) will send the telemetry data. Each edge device might be collecting data from around 500 devices.

I am looking for a guidance on logical steps involved and a few critical pieces of Python code


Solution

  • Are these telemetry messages or property changes? Also what's the scale (number of devices)? To do this effectively you need to ensure you have both the current and previous values, which means storing the last reported value and timestamp externally as it could be a long time between. The Event Hub is not guaranteed to have all past messages (default is 24h), so if there's a long lag between messages it's not the right store to rely on.

    Durable Entities can be used to store state (using something similar to the Actor Model). These are persisted in Azure Storage so at extremely high throughput a memory-only calculation option might make sense with delayed persistence, but you can build a memory-caching layer into your function to help if needed. This is likely going to be the best bet for what you want to do.

    For most people the performance hit of going to Azure storage and back is minimal and Durable Entities will be the easiest path forward.