Azure Stream Analytics – A Simple Proof-Of-Concept

In my last post I gave a high level overview of the CallStats proof-of-concept app that I built using Azure Stream Analytics, in this post I’m going to explain how to get it running for yourself.

Prerequisites

You will need an Azure subscription with the Stream Analytics preview enabled.

Setting up Service Bus

The first step is to configure some Event Hubs, these will be the ingest and output for Stream Analytics.

  1. From the Azure portal (http://manage.windowsazure.com) create a new Service Bus namespace, (make a note of this, as you will need it when configuring the projects).
  2. Create a new Event Hub called CallStatsIn with 8 partitions
    1. Create a shared access policy with the Manage, Send and Listen permissions
    2. Make a note of the connection string for this policy
  3. Create another Event Hub, this time called CallStatsOut with 8 partitions
    1. Create a shared access policy with the Manage, Send and Listen permissions
    2. Make a note of the policy name and the primary key

Setting up Stream Analytics

The next step is to configure a new Stream Analytics job

  1. From the Stream Analytics section in the Azure portal create a new job, you can call it whatever you like
  2. Select the Input tab, and create a new event hub input called CallStatsIn specifying JSON as the serialization format
  3. Select the Output tab and create a new event hub output called CallStatsOut, specifying JSON as the serialization format
  4. Select the Query tab, and paste the following query:
SELECT
    ConnectionName, 
    DateAdd(second,-5,System.TimeStamp) as WinStartTime, 
    System.TimeStamp as WinEndTime, 
    Sum(CASE WHEN EventType=1 THEN 1 ELSE 0 END) as Started,
    Sum(CASE WHEN EventType=2 THEN 1 ELSE 0 END) as Ended,
    Sum(CASE WHEN EventType=3 THEN 1 ELSE 0 END) as Dropped,
    Sum(CASE WHEN EventType=4 THEN 1 ELSE 0 END) as NotAnsweredBusy
FROM 
    callstatsin
GROUP BY 
    HoppingWindow(second, 5, 1), ConnectionName

Setting up the Solution

Download my sample solution from GitHub (https://github.com/kzhen/StreamAnalytics/archive/master.zip).

  1. Open in Visual Studio (as an administrator)
  2. Open the App.config file in the Consumer project
    1. Set ServiceBus.Namespace to the namespace you created above
    2. Set ServiceBus.KeyName to the name of the shared access policy for CallStatsOut Event Hub
    3. Set ServiceBus.Key to the Primary Key for the CallStatsOut Event Hub
  3. Open the App.config file in the CallProducer project
    1. Set Microsoft.ServiceBus.ConnectionString to the connection string for the CallStatsIn Event Hub

Running the Solution

Build the solution then start each project. You should see output in each of the console projects and the graph on the webpage should start updating

Advertisements

3 thoughts on “Azure Stream Analytics – A Simple Proof-Of-Concept

  1. sachabarber says:

    I have just started looking into the EventHub / stream analytics, and this post and the code with it look just the ticket to get started, thanks so much

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s