Azure Stream Analytics
Overview
Azure Stream Analytics (ASA) is a real‑time analytics service that processes high‑volume data streams from devices, sensors, websites, and applications. It provides built‑in integration with Azure Event Hubs, IoT Hub, and Blob storage, allowing you to create low‑latency, event‑driven pipelines without managing infrastructure.
Key Concepts
A job defines the processing pipeline, including input, query, and output definitions. Jobs run continuously and can be scaled by adjusting streaming units.
Supported input sources: Event Hubs, IoT Hub, Azure Blob storage, Azure Data Lake Store, and Azure SQL Database.
Targets include Azure SQL Database, Azure Synapse, Azure Cosmos DB, Blob storage, Power BI, and custom endpoints via Azure Functions.
ASA uses a SQL‑like language for streaming analytics. Queries can include temporal joins, window functions, and user‑defined functions.
SELECT
System.Timestamp AS WindowEnd,
DeviceId,
AVG(Temperature) AS AvgTemp
INTO
PowerBIAnalytics
FROM
IoTHubInput TIMESTAMP BY EventEnqueuedUtcTime
GROUP BY
TumblingWindow(minute, 5), DeviceId;
Pricing
| Component | Cost |
|---|---|
| Streaming Units (SU) | $0.11 per SU per hour |
| Input (Event Hubs/IoT Hub) | Based on ingress volume |
| Output (Blob/SQL/Power BI) | Based on egress volume |
| Data Retention (Job storage) | Free for first 5 GB, then $0.03 per GB |
Getting Started
- Create an Azure Stream Analytics job via the Azure portal.
- Configure inputs (e.g., an IoT Hub endpoint).
- Write a query using the ASA query language.
- Set up one or more outputs (e.g., Azure SQL Database, Power BI).
- Start the job and monitor metrics in real time.
For a step‑by‑step tutorial, see the Stream Analytics Quickstart.
Sample Code
Below is a simple C# example that creates a Stream Analytics job programmatically using the Azure Management SDK.
using Azure;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.StreamAnalytics;
using Azure.ResourceManager.StreamAnalytics.Models;
var credential = new DefaultAzureCredential();
var armClient = new ArmClient(credential);
var subscription = await armClient.GetDefaultSubscriptionAsync();
var resourceGroup = await subscription.GetResourceGroups().GetAsync("myResourceGroup");
var jobData = new StreamAnalyticsJobData(location: "EastUS")
{
Sku = new StreamAnalyticsSku("Standard")
{
Capacity = 1
}
};
var jobLro = await resourceGroup.Value.GetStreamAnalyticsJobs()
.CreateOrUpdateAsync(WaitUntil.Completed, "myASAJob", jobData);
var job = jobLro.Value;
Console.WriteLine($"Created job with ID: {job.Id}");