<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Configure Stream Analytics with Input and Output &#8211; Sibeesh Passion</title>
	<atom:link href="https://sibeeshpassion.com/tag/configure-stream-analytics-with-input-and-output/feed/" rel="self" type="application/rss+xml" />
	<link>https://sibeeshpassion.com</link>
	<description>My passion towards life</description>
	<lastBuildDate>Fri, 11 Jan 2019 09:41:22 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>/wp-content/uploads/2017/04/Sibeesh_Passion_Logo_Small.png</url>
	<title>Configure Stream Analytics with Input and Output &#8211; Sibeesh Passion</title>
	<link>https://sibeeshpassion.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>An Introduction to Azure Stream Analytics Job</title>
		<link>https://sibeeshpassion.com/an-introduction-to-azure-stream-analytics-job/</link>
					<comments>https://sibeeshpassion.com/an-introduction-to-azure-stream-analytics-job/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Tue, 11 Dec 2018 14:00:39 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[IoT]]></category>
		<category><![CDATA[Azure IoT]]></category>
		<category><![CDATA[Azure SQL]]></category>
		<category><![CDATA[Configure Stream Analytics with Input and Output]]></category>
		<category><![CDATA[Data Lake]]></category>
		<category><![CDATA[IoT Hub]]></category>
		<category><![CDATA[MXChip]]></category>
		<category><![CDATA[Stream Analytics Job]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=13444</guid>

					<description><![CDATA[[toc] Introduction The capability of an Azure Stream Analytics Job is a lot, here in this post we are going to discuss a few of them. An Azure Stream Analytics is basically an engine which processes the events. These events are coming from the devices we have configured, it can be an Azure IoT Dev Kit (MXChip) or a Raspberry Pi and many more. The stream analytics job has two vital parts Input source Output source The input source is the source of your streaming data, in my case, it is my IoT Hub. And the output source is the output [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>[toc]</p>



<h2 class="wp-block-heading">Introduction</h2>



<p>The capability of an <a href="https://sibeeshpassion.com/category/azure/">Azure</a> Stream Analytics Job is a lot, here in this post we are going to discuss a few of them. An Azure Stream Analytics is basically an engine which processes the events. These events are coming from the devices we have configured, it can be an Azure IoT Dev Kit (MXChip) or a <a href="https://sibeeshpassion.com/category/raspberry-pi/">Raspberry Pi</a> and many more. The stream analytics job has two vital parts</p>



<ul class="wp-block-list"><li>Input source</li><li>Output source</li></ul>



<p>The input source is the source of your streaming data, in my case, it is my IoT Hub. And the output source is the output what you are configuring. I had configured the output to save the data to an Azure SQL database. Let&#8217;s just stop the introduction part now and start creating our own Stream Analytics. </p>



<div class="wp-block-image"><figure class="aligncenter is-resized"><img decoding="async" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/stream-analytics-intro-pipeline.png" alt="" class="wp-image-13445" width="650"/><figcaption>docs.microsoft.com</figcaption></figure></div>



<h2 class="wp-block-heading">Background</h2>



<p>I recently got my MXChip (Azure Iot Dev Kit) and I was surprised with the capabilities that device can do.&nbsp;It has a lot of sensors within the device, like temperature, humidity, pressure, magnetometer, security etc. Then I thought it is time to play with the same.&nbsp;So the basic idea here was to,</p>



<ol class="wp-block-list"><li>Configure the device to send the data to the IoT Hub</li><li>Select the IoT Hub as a stream input</li><li>Send the output to an SQL Server database</li></ol>



<p>In this article, we are going to concentrate on how to create a Stream Analytics Job and how you can configure the same to save the stream data to the SQL Server database.&nbsp;</p>



<h2 class="wp-block-heading">Prerequisites</h2>



<p>To do the wonderful things, we always need some prerequisites.&nbsp;&nbsp;</p>



<ol class="wp-block-list"><li>Azure Subscription</li><li>MXChip Azure IoT Dev Kit&nbsp;</li><li>An active IoT Hubows Driver Kit (WDK) 10</li><li>IoT Core ADK Add-Ons</li><li>Windows 10 IoT Core Packages</li><li>The Raspberry Pi BSP</li><li>Custom FFU image we have created</li></ol>



<h2 class="wp-block-heading">Creating the Azure Stream Analytics Job</h2>



<p>Login to your Azure Portal and click on the Create a resource, and then search for the &#8220;Stream Analytics job&#8221;.&nbsp;</p>



<div class="wp-block-image"><figure class="aligncenter"><img fetchpriority="high" decoding="async" width="520" height="321" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Stream-Analytics-Outputs.jpg" alt="" class="wp-image-13446" srcset="/wp-content/uploads/2018/12/Stream-Analytics-Outputs.jpg 520w, /wp-content/uploads/2018/12/Stream-Analytics-Outputs-300x185.jpg 300w, /wp-content/uploads/2018/12/Stream-Analytics-Outputs-400x247.jpg 400w" sizes="(max-width: 520px) 100vw, 520px" /></figure></div>



<p>Once you clicked on the Create button, it is time to specify the details of your job.</p>



<ol class="wp-block-list"><li>Job Name</li><li>Subscription</li><li>Resource Group</li><li>Location</li><li>Hosting Environment</li><li></li></ol>



<p>I would strongly recommend you to&nbsp;select the same resource group of your IoT Hub for the Stream Analytics Job as well so that you can easily delete the resources when there are not needed. Once the deployment is successful you can go to the resource overview and see the details.</p>



<h3 class="wp-block-heading">Configure Inputs</h3>



<p>In the left menu, you can see a section called Job topology, that&#8217;s where we are going to work. Basically, we will be setting the Inputs and Outputs and then we will be writing a query which can take the inputs and send the values to the configured output.&nbsp;Click on the Inputs label and click on Add stream input and then select the IoT Hub.</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="480" height="452" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Configure-the-Input-in-Stream-Analytics.jpg" alt="Configure the Input in Stream Analytics" class="wp-image-13447" srcset="/wp-content/uploads/2018/12/Configure-the-Input-in-Stream-Analytics.jpg 480w, /wp-content/uploads/2018/12/Configure-the-Input-in-Stream-Analytics-300x283.jpg 300w, /wp-content/uploads/2018/12/Configure-the-Input-in-Stream-Analytics-400x377.jpg 400w" sizes="(max-width: 480px) 100vw, 480px" /></figure></div>



<p>In the next screen, you will have options to select the existing IoT hub and to create a new IoT Hub. As I have already created an IoT hub, I would select the existing one. </p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Please be noted that you are allowed to use special characters in the Input alias field, but if you use such, please make sure to include the same inside [] in the query, which we will be creating later.&nbsp;</p><cite>About the special characters in Input alias field</cite></blockquote>



<p>Once you are successfully&nbsp;configured the Inputs, then we can go ahead and configure the outputs. </p>



<h3 class="wp-block-heading">Configure Outputs</h3>



<p>Click on the Outputs from the Job topology section and click Add, and then select <g class="gr_ gr_144 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar only-ins replaceWithoutSep" id="144" data-gr-id="144">SQL</g> Database.</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="474" height="448" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Configure-the-Output-in-Stream-Analytics.jpg" alt="Configure the Output in Stream Analytics" class="wp-image-13448" srcset="/wp-content/uploads/2018/12/Configure-the-Output-in-Stream-Analytics.jpg 474w, /wp-content/uploads/2018/12/Configure-the-Output-in-Stream-Analytics-300x284.jpg 300w, /wp-content/uploads/2018/12/Configure-the-Output-in-Stream-Analytics-400x378.jpg 400w" sizes="(max-width: 474px) 100vw, 474px" /></figure></div>



<p>You can either create a new Database&nbsp;or select the one you had already created. I used the existing database and table.&nbsp;</p>



<h3 class="wp-block-heading">Configure the Query</h3>



<p>Once you click the label Query on the left pan, you will be given an editor where you can write your queries. I am using the below query.&nbsp;</p>



<pre class="wp-block-code"><code>SELECT
    messageId,
    deviceId,
    temperature,
    humidity,
    pressure,
    pointInfo,
    IoTHub,
    EventEnqueuedUtcTime,
    EventProcessedUtcTime,
    PartitionId
INTO
    streamoutputs
FROM
    streaminputs</code></pre>



<p>As you can see that I am just selecting the fields I may need and saving the same to our stream outputs. You can always select all the fields by using the select * query, but the problem with that is, you will have to set up the table columns in the same order of the stream data. Otherwise, you may get an error as below.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Encountered error trying to write 1 event(s): Failed to locate column &#8216;IoTHub&#8217; at position 6 in the output event</p><cite>Stream analytics query error</cite></blockquote>



<p>If there are any errors, you can see that in the Output details.</p>



<h2 class="wp-block-heading">Run the Stream Analytics Job and See the Data in the Database</h2>



<p>As we have already done the initial set up, we can now start our Stream Analytics Job, please make sure that the IoT Hub is running and the device is sending data to the IoT Hub. If everything is working as expected, you will be able to see the data in the SQL server database. You can either connect your MXChip device to the network and test this or use the custom <a href="https://github.com/Azure-Samples/azure-iot-samples-csharp/tree/master/iot-hub/Tutorials/Routing/SimulatedDevice">simulator app</a>.&nbsp;</p>



<p>If you are using the Simulator console application, make sure that you are giving the device id, key and the IoT hub uri correctly, otherwise you will get an unauthorized error as explained <a href="https://stackoverflow.com/questions/53708530/microsoft-azure-devices-client-exceptions-unauthorizedexception-connect-failed/53708531#53708531">here</a>.&nbsp;</p>



<h3 class="wp-block-heading">Test the Stream Analytics Job Inside the Portal</h3>



<p>You also have an option to test the functionality in the portal itself. The only thing you will have to do is to prepare the sample input data. I have prepared the sample JSON data as follows. </p>



<pre class="wp-block-code"><code>[
  {
    "deviceId": "test-device",
    "humidity": 77.699449415178719,
    "pointInfo": "This is a normal message.",
    "temperature": 32.506656929620846
  },
  {
    "deviceId": "test-device",
    "temperature": 52.506656929620846,
    "humidity": 17.699449415178719,
    "pointInfo": "This is a normal message."
  },
  {
    "deviceId": "test-device",
    "temperature": 42.506656929620846,
    "humidity": 57.699449415178719,
    "pointInfo": "This is a normal message."
  }
]

</code></pre>



<p>Now we can go to the Query section and upload the sample data file for our inputs.&nbsp;</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="650" height="342" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Test-the-Stream-Analytics-with-Sample-Data.jpg" alt="" class="wp-image-13449" srcset="/wp-content/uploads/2018/12/Test-the-Stream-Analytics-with-Sample-Data.jpg 650w, /wp-content/uploads/2018/12/Test-the-Stream-Analytics-with-Sample-Data-300x158.jpg 300w, /wp-content/uploads/2018/12/Test-the-Stream-Analytics-with-Sample-Data-600x315.jpg 600w, /wp-content/uploads/2018/12/Test-the-Stream-Analytics-with-Sample-Data-400x210.jpg 400w" sizes="(max-width: 650px) 100vw, 650px" /></figure></div>



<p>In the next window, you can select the JSON option and upload your JSON file.&nbsp;</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="520" height="188" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Upload-the-test-data.jpg" alt="" class="wp-image-13450" srcset="/wp-content/uploads/2018/12/Upload-the-test-data.jpg 520w, /wp-content/uploads/2018/12/Upload-the-test-data-300x108.jpg 300w, /wp-content/uploads/2018/12/Upload-the-test-data-400x145.jpg 400w" sizes="(max-width: 520px) 100vw, 520px" /></figure></div>



<p>Click the Test button, and now you should be able to see the output as below.</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="650" height="325" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Test-with-Sample-Data-Output.jpg" alt="" class="wp-image-13451" srcset="/wp-content/uploads/2018/12/Test-with-Sample-Data-Output.jpg 650w, /wp-content/uploads/2018/12/Test-with-Sample-Data-Output-300x150.jpg 300w, /wp-content/uploads/2018/12/Test-with-Sample-Data-Output-400x200.jpg 400w" sizes="(max-width: 650px) 100vw, 650px" /></figure></div>



<h2 class="wp-block-heading">Conclusion</h2>



<p>Wow!. Now we have learned,</p>



<ul class="wp-block-list"><li>What is Azure Stream Analytics Job</li><li>how to create Azure Stream Analytics Job</li><li>how to add Inputs to the Azure Stream Analytics</li><li>how to add Outputs to the Azure Stream Analytics</li><li>how to add custom Query in Azure Stream Analytics</li><li>how to Test the Stream Analytics Query with sample data</li></ul>



<p>You can always ready my IoT articles <a href="https://sibeeshpassion.com/category/iot/">here</a>.</p>



<h2 class="wp-block-heading">Your turn. What do you think?</h2>



<p>Thanks a lot for reading. Did I miss anything that you may think which is needed in this article? Could you find this post as useful? Kindly do not forget to share me your feedback.</p>



<p>Kindest Regards<br>Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/an-introduction-to-azure-stream-analytics-job/feed/</wfw:commentRss>
			<slash:comments>8</slash:comments>
		
		
			</item>
	</channel>
</rss>
