>> Welcome to Azure Tips and Tricks.
In this episode, we are going to use
Azure Stream Analytics to query streaming data.
We will use a relatively complex setup with various components.
A Raspberry Pi simulator will generate data for us,
which we will ingest with Azure IoT Hub.
Azure Stream Analytics will get the data from Azure IoT Hub,
query it and transform it and send the results to Azure Storage.
Let's start by creating an Azure IoT Hub.
First, I'll select a resource group
and now give the hub a name like this.
I'll leave the rest as it is and create.
I'll skip to when it is done.
Here is the IoT Hub.
To be able to ingest data,
it needs a device to connect with it.
Here, let's create one.
Enter a name for the device and that's it.
This device is the digital representation
of a real world device that we connect later.
To do that, I need this connection string. Let's move on.
IoT Hub serves as the input for stream analytics,
and when the data is queried,
it will be put somewhere in a new Azure Storage account.
Again, let's pick
the resource group and also enter a name for the account,
like this and I'll leave the rest and create it.
Again, I'll skip ahead.
Here is the storage account.
Stream Analytics will write
blob files so it will need a blob container for that.
Let's create a new one.
I'll keep the name very simple.
I'll also leave the access level to private.
Create a container, and that's it.
We need to create one final thing.
The stream analytics job.
This is the thing that will query the data stream.
Let's give the job a name.
I'll pick a resource group,
and I'll pick the same location as
the other services are in so that they
are close together and work fast.
The hosting engine should be Cloud
because we run this in the Azure Cloud.
Also, these are enough streaming units.
You can scale this up if you need
more power to process the data stream.
Create it, and I'll skip to when it is done.
Here is the Stream Analytics job.
Let's tie everything together.
This job needs an input and an output.
Let's add an input first.
That will be the IoT Hub.
I'll give the input a name, That should be it.
It already selected the hub that we created earlier.
Perfect. That's it.
Now for the output,
let's add a new output.
This will be a blob storage output.
I will also give this one a name.
I need to pick the storage accounts that we just created.
Here it is. This is the right container as well.
I'll leave the authentication mode
to work with a managed identity.
That should work automatically.
Save it, and that's it.
Now for the query,
this is the query that analyzes the real time data stream.
I'll change it into this.
These are the names for the input and output,
and it will query for data that contains a temperature above 27.
This job is complete.
It has an input,
an output and a query.
Now we need to start it. That should be it.
Here is the Raspberry Pi online simulator.
You can find a link to this in the video description.
This needs to connect to IoT hub.
I can do that by replacing this line with
the device connection string that we copied earlier. That's it.
Now run the simulator, and it is sending messages.
These come into the stream analytics job and will be queried.
They should be outputted here in Azure Storage. Let's take a look.
This JSON file is the result of the Stream Analytics query,
and it only contains messages of temperature data above 27.
As your stream analytics is great for querying
streaming data to reveal relevant information.
Go and check it out.