Azure Stream Analytics–reading events from EventHub, running query and saving results to ServiceBus
This blog is part of IoT Series, where I am trying to build few IoT devices that push events to Azure EventHub. From the EventHub, Azure Stream Analytics will execute my query to calculate average values for each individual device and publish these average values to Azure ServiceBus. From Azure ServiceBus, I am going to read the average values in Azure Functions Apps and save them into Azure Redis Cache. My Azure Website will poll this Redis Cache and displays the average values.
Here are list of blog posts in this series:
-
-
- Azure IoT
- Azure EventHub–sending IoT device events to EventHub
- Azure ServiceBus Queue–reading query results from Stream Analytics
- Azure Stream Analytics–reading events from EventHub, running query and saving results to ServiceBus
- Azure Function Apps – reading events from ServiceBus and writing to Redis Cache
-
In this blog, I am going to show how to configure Azure Stream Analytics to read from Azure EventHub, run Query and save results to Azure ServiceBus.
-
Login to Azure Portal (https://portal.Azure.com)
Click on + New button
In the Search, type Stream Analytics
Select Stream Analytics Jobs and click Create button
Click on Create button
Once this Stream Analytics Job is deployed, navigate to this newly created Stream Analytics Job
Click on the Overview, select Input, click Add and in the New Input select the source as EventHub as shown below
Now select the Output, click on Add button and set the New Output source to ServiceBus Queue as show below
Now set the query, click on Query, in the query editor type this below query
SELECT DeviceName, AVG(temperature) as AvgTemp, AVG(speed) as AvgSpeed FROM fromWabacEventHub TIMESTAMP BY datetime Group BY DeviceName, TumblingWindow(second, 10)
Now start the Stream Analytics Job, by clicking on the Start button
To check if the query is getting executed and results are saved to ServiceBus, in the console app run these two functions SendEvents(10) and CheckIfServiceBusGotEvents()
Complete code is here
Next, we will configure Azure Function Apps to read from Azure ServiceBus and write it to Azure Redis Cache. Click here for next blog