Freigeben über


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:

      1. Azure IoT
      2. Azure EventHub–sending IoT device events to EventHub
      3. Azure ServiceBus Queue–reading query results from Stream Analytics
      4. Azure Stream Analytics–reading events from EventHub, running query and saving results to ServiceBus
      5. 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.

    1. Login to Azure Portal (https://portal.Azure.com)

    2. Click on + New button

    3. In the Search, type Stream Analytics

    4. Select Stream Analytics Jobs and click Create button

    5. Provide name and resource group as show below
      SA_new

    6. Click on Create button

    7. Once this Stream Analytics Job is deployed, navigate to this newly created Stream Analytics Job

    8. Click on the Overview, select Input, click Add and in the New Input select the source as EventHub as shown below
      SA_Input

    9. Now select the Output, click on Add button and set the New Output source to ServiceBus Queue as show below
      SA_Output

    10. 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)
      

      SA_Query

    11. Now start the Stream Analytics Job, by clicking on the Start button

    12. 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()

    13. Complete code is here

    14. Next, we will configure Azure Function Apps to read from Azure ServiceBus and write it to Azure Redis Cache. Click here for next blog