One question that comes up a lot when getting started with IoT is 'How do I store all this data?'. This is an important question - IoT creates a LOT of data, some of which can be analyzed on the fly, but there are a large number of cases where you want to run analytics later, or have access to historical raw data to run new analytics later.
IoT typically involves ingesting a large number of messages through a single hub, and these hubs are typically dumb - in that they provide a single point to ingest the messages but don't do anything with them. That's the responsibility of the developers building out the IoT solution.
One area that is powerful with Azure IoT is Azure Stream Analytics. This is a service that can be connected to any event stream, such as an IoT Hub, and take the live stream of data and do something with it, such as filter, manipulate and output to other systems. You can even wire up ML based anomaly detection to be alerted when unexpected values are received.
In this post we will see how to use Stream Analytics to stream IoT data into a database. This assumes you already have an IoT hub receiving data.
The first thing you need is a database to put the data into. Stream analytics works with both Azure Cosmos DB and Azure SQL Database, as well as many other storage solutions, so it's up to you which one you want to use. In this post I'll use Cosmos DB, but the concepts apply to all data stores.
Once you have the database, you need to create a Stream Analytics resource.
Stream analytics allows you to define inputs, outputs and queries. Queries query inputs and can push data into outputs, so you can query all items from an IoT Hub and select them into a Cosmos DB database. These queries run on the stream as data is received, and output as each item is processed - these are not like traditional SQL queries that run synchronously against a static set of data.
SELECT * INTO [cosmos-db] FROM [iot-hub]
Once data comes in, you will be able to see it appear in Cosmos DB.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.