Azure Cosmos DB is Microsoft's globally distributed, multi-model database. The atom-record-sequence (ARS) based data model that Azure Cosmos DB is built on natively supports multiple data models, including but not limited to document, graph, key-value, table, and column-family data models
Elastically and independently scale throughput and storage on demand and worldwide
Azure Cosmos DB provides five consistency levels: strong, bounded-staleness, session, consistent prefix, and eventual.
In this lab you will learn
- how to set up a CosmosDB
- streaming analytics with windowing techniques
- to Store Time Series Data in CosmosDB
Click on Create a resource
Click on Databases
Click on Azure Cosmos DB
For this tutorial we will use SQL API.
Available APIs are
- SQL API: A schema-less JSON database engine with rich SQL querying capabilities.
- MongoDB API: A massively scalable MongoDB-as-a-Service powered by Azure Cosmos DB platform. Compatible with existing MongoDB libraries, drivers, tools, and applications.
- Cassandra API: A globally distributed Cassandra-as-a-Service powered by Azure Cosmos DB platform. Compatible with existing Apache Cassandra libraries, drivers, tools, and applications.
- Graph (Gremlin) API: A fully managed, horizontally scalable graph database service that makes it easy to build and run applications that work with highly connected datasets supporting Open Graph APIs (based on the Apache TinkerPop specification, Apache Gremlin).
- Table API: A key-value database service built to provide premium capabilities (for example, automatic indexing, guaranteed low latency, global distribution) to existing Azure Table storage applications without making any app changes
To Add Cosmos DB as output to Stream Analytics Job you will need to Stop the job, Add Cosmos DB output and corresponding Query and Start the job
Add Cosmos DB as an Output to Stream Analytics Job
Select Cosmos DB as an output. Also make sure you create a new Database and a collection if its is not already created
Edit existing query to Add new query to consume data from IoTHub and store data into Cosmos DB
SELECT
*, System.Timestamp as time
INTO
CosmosDB
FROM
IotHub
GROUP BY deviceId, TumblingWindow(second,30)
Start Stream Analytics Job
Make sure you stream all the data from when you last stopped the job. Stream Analytics interface provides an option
Make sure Stream Analytics job goes into running mode
Use Cosmos DB data explorer to view data being streamed from IoTHub to Cosmos DB