An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
Hello @Georg Sieber,
Your scenario is great use-case and indeed a helpful post for many users who want to do benchmarking with various solutions!!!! I really like the way you have tried many different solutions!!! this is a helpful post on this forum!!!
Currently, we use a dedicated service process we wrote to consume all messages from the built-in endpoint, stores them in-memory until one of the criteria from above is met and then writes the output file per device.
It may not be the most scalable or fault-tolerant approach, especially as the number of devices and messages increases in future!!!
One alternative approach you could consider is to use Azure Stream Analytics (ASA) as suggested in the previous response by Matthijs (MVP) and i see that you have already tried that route!
My favourite way would be to just use the builtin route to azure storage. However, it is not possible to split the output by device there.
You are correct that the built-in route to Azure Storage in Azure IoT Hub doesn't support splitting the output by device. One approach you could take is to use Azure Functions
I tried to use a Azure stream analytics jobs to perform this but could not configure the input correctly since the messages are just binary blobs.
It's true ASA require some additional configuration and setup, with binary blobs as input data!!!!
One alternative approach you could consider is to use Azure Functions to process the messages from the IoT Hub and write them to your storage endpoint in batches.
Do you have any other ideas or are there any available solutions for this scenario since i would suppose this to be a quite common scenario.
You can try the Azure Functions, serverless and highly scalable, as Azure Functions automatically scales to meet demand and only charges for the compute resources used during each execution.
You can use an IoT Hub trigger to automatically invoke an Azure Function whenever a message is received by the IoT Hub. Inside the Azure Function, you can then use the device ID to group the incoming messages by device and create a batch and you can forward the batch to your desired destination (e.g. storage endpoint or queue).
a small sample snippet of the Azure functions may look like below...!
foreach (EventData eventData in events)
{
// Extract the device ID from the incoming message
string deviceId = eventData.SystemProperties["iothub-connection-device-id"].ToString();
// Add the message to the device's message cache
if (!deviceMessageCache.ContainsKey(deviceId))
{
deviceMessageCache[deviceId] = new List<EventData>();
}
deviceMessageCache[deviceId].Add(eventData);
// Check if the device's message cache meets the batch criteria
if (deviceMessageCache[deviceId].Count >= 500 || (DateTime.UtcNow - eventData.SystemProperties.EnqueuedTimeUtc).TotalMinutes >= 5)
{
// Create a batch and forward it to the desired destination
List<EventData> messageBatch = deviceMessageCache[deviceId];
deviceMessageCache[deviceId] = new List<EventData>();
await ForwardMessageBatchAsync(deviceId, messageBatch);
}
}
private static async Task ForwardMessageBatchAsync(string deviceId, List<EventData> messageBatch)
{
// Forward the message batch to the desired destination (e.g. storage endpoint or queue)
// ...
}
If this answers your query, do click Accept Answer and Yes for this answer as helpful. And, if you have any further query do let us know by commenting in the below section.