<?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>Stream Analytics Job &#8211; Sibeesh Passion</title>
	<atom:link href="https://mail.sibeeshpassion.com/tag/stream-analytics-job/feed/" rel="self" type="application/rss+xml" />
	<link>https://mail.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>Stream Analytics Job &#8211; Sibeesh Passion</title>
	<link>https://mail.sibeeshpassion.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Azure Function as Output Job Topology of an Azure Stream Analytics Job</title>
		<link>https://mail.sibeeshpassion.com/azure-function-as-output-job-topology-of-an-azure-stream-analytics-job/</link>
					<comments>https://mail.sibeeshpassion.com/azure-function-as-output-job-topology-of-an-azure-stream-analytics-job/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Wed, 19 Dec 2018 14:37:18 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[IoT]]></category>
		<category><![CDATA[ASA]]></category>
		<category><![CDATA[Azure Function]]></category>
		<category><![CDATA[Azure Function and Azure Stream Analytics]]></category>
		<category><![CDATA[Azure IoT]]></category>
		<category><![CDATA[IoT Hub]]></category>
		<category><![CDATA[MXChip]]></category>
		<category><![CDATA[Stream Analytics Job]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=13479</guid>

					<description><![CDATA[[toc] Introduction For the last few days, I am playing with my Azure IoT Dev Kit MXChip. In this article, we are going to see how we can set up an Azure Function as an Output job topology of an Azure Stream Analytics job. Isn&#8217;t that sound interesting? In our previous articles, we have already seen what is an Azure Stream Analytics Job and How can we create in by using the portal and Visual Studio. If you haven&#8217;t read those articles, I strongly recommend you to read. Let&#8217;s jump on to this article now. Background As I have mentioned [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>[toc]</p>



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



<p>For the last few days, I am playing with my Azure IoT Dev Kit MXChip. In this article, we are going to see how we can set up an Azure Function as an Output job topology of an Azure Stream Analytics job. Isn&#8217;t that sound interesting? In our previous <a href="https://sibeeshpassion.com/tag/stream-analytics-job/">articles</a>, we have already seen what is an Azure Stream Analytics Job and How can we create in by using the portal and Visual Studio. If you haven&#8217;t read those articles, I strongly recommend you to read. Let&#8217;s jump on to this article now.</p>



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



<p>As I have mentioned earlier, in this article we will be,&nbsp;</p>



<ol class="wp-block-list"><li>using our existing Azure Stream Analytics job.</li><li>creating a new Azure Function App.</li><li>setting up the newly created Azure function as an output job topology of the stream analytics job.</li><li>monitoring the data coming to the Azure Function from the stream analytics job.</li></ol>



<h2 class="wp-block-heading">Play with Azure Function</h2>



<p>Yeah, we are going to play with it. Let&#8217;s go and create one then.</p>



<h3 class="wp-block-heading">Creating an Azure Function</h3>



<p>To create an Azure Function application, you need to login to your Azure portal and click on the Create a resource icon, and then you can search for the &#8221; Function App&#8221;.&nbsp;</p>



<p>In the next screen, provide the following information.&nbsp;</p>



<ol class="wp-block-list"><li>App Name</li><li>Subscription</li><li>Resource Group</li><li>OS</li><li>Hosting plan</li><li>Location&nbsp;</li><li>Runtime stack</li><li>Storage</li><li>Application Insights</li></ol>



<p>Here the consumption plan hosting plan allows you to pay per execution, and the App service plan allows you to have a predefined capacity. For the runtime stack, we will use .NET, however, you are free to use anything you wish.&nbsp;</p>



<p>Once you have created the same, you should be able to see it under the Function Apps section.&nbsp;</p>



<h3 class="wp-block-heading">Creating an Azure Function Solution and Function</h3>



<p>Now let&#8217;s go to our Visual Studio and create a new solution for our Azure Function.&nbsp;</p>



<div class="wp-block-image"><figure class="aligncenter is-resized"><img fetchpriority="high" decoding="async" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Azure-Function-Project-Type-1024x419.jpg" alt="" class="wp-image-13480" width="512" height="210" srcset="/wp-content/uploads/2018/12/Azure-Function-Project-Type-1024x419.jpg 1024w, /wp-content/uploads/2018/12/Azure-Function-Project-Type-300x123.jpg 300w, /wp-content/uploads/2018/12/Azure-Function-Project-Type-768x314.jpg 768w, /wp-content/uploads/2018/12/Azure-Function-Project-Type-400x163.jpg 400w, /wp-content/uploads/2018/12/Azure-Function-Project-Type.jpg 1375w" sizes="(max-width: 512px) 100vw, 512px" /><figcaption>Azure Function Project Type</figcaption></figure></div>



<p>Now you can right click on your newly created project and add a new HttpTrigger Function. We will keep the Access Rights to Anonymous for now. I have named my function as &#8220;GetData&#8221;. For now, let&#8217;s just get the data from our Stream Analytics job and just check the length.&nbsp;</p>



<pre class="wp-block-code"><code>using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;

namespace ml.IoTPlatform.AzureFunctions
{
    public static class GetData
    {
        [FunctionName("GetData")]
        public static async Task&lt;HttpResponseMessage> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post")]HttpRequestMessage req,
            ILogger log)
        {
            log.LogInformation($"GetData function triggered with Uri {req.RequestUri}");

            string content = await req.Content.ReadAsStringAsync();
            log.LogInformation($"String content is {content}");
            dynamic data = JsonConvert.DeserializeObject(content);

            log.LogInformation($"Data count is {data?.Count}");

            if (data?.ToString()?.Length > 262144)
            {
                return new HttpResponseMessage(HttpStatusCode.RequestEntityTooLarge);
            }

            return req.CreateResponse(HttpStatusCode.OK, "Success");
        }
    }
}</code></pre>



<p>As you can see we are not doing nothing much for now, we are just receiving the data as&nbsp;HttpRequestMessage and we are reading the content as&nbsp;req.Content.ReadAsStringAsync() and then deserialize the object. If you are not doing this step, you may get an error as&nbsp;&#8220;<strong>No MediaTypeFormatter is available to read an object of type &#8216;Object&#8217; from content with media type &#8216;application/octet-stream&#8217;.</strong>&#8220;</p>



<p>We are also checking the entity length, and if it is too large we are sending a&nbsp;HttpResponseMessage with status code 413.&nbsp;</p>



<h3 class="wp-block-heading">Publish the Azure Function App</h3>



<p>To publish your Azure Function app, just right click on your project and click Publish and then set up your publish target by choosing the existing Azure Function App, remember we have created on earlier? Once you publish the same, you can go into your Function App and see your Function. You can also test the same with some dummy data.&nbsp;</p>



<p>There are probabilities to get an error as &#8220;<strong>Web Deploy cannot modify the file on the destination because it is locked by an external process</strong>&#8221; when you try to publish your Function App from Visual Studio, while your Function App is running, to fix this you can see my answer <a href="https://stackoverflow.com/questions/37918650/azure-web-app-deploy-web-deploy-cannot-modify-the-file-on-the-destination-becau/53833766#53833766">here</a>.&nbsp;</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="651" height="284" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Function-App-in-Portal.jpg" alt="" class="wp-image-13481" srcset="/wp-content/uploads/2018/12/Function-App-in-Portal.jpg 651w, /wp-content/uploads/2018/12/Function-App-in-Portal-300x131.jpg 300w, /wp-content/uploads/2018/12/Function-App-in-Portal-400x175.jpg 400w" sizes="(max-width: 651px) 100vw, 651px" /><figcaption>Function App in Portal</figcaption></figure></div>



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



<p>Let&#8217;s go back to our Azure Stream Analytics now as we have already configured our Azure Function App successfully.&nbsp;</p>



<h3 class="wp-block-heading">Configure Azure Function Output</h3>



<p>In my previous <a href="https://sibeeshpassion.com/azure-stream-analytics-job-and-tools-for-visual-studio/">article</a>, we had created an Azure Stream Analytics job solution using Visual Studio, let&#8217;s open that solution now and configure the new output for Azure Function.&nbsp;</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="640" height="535" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Solution-Explorer.jpg" alt="" class="wp-image-13482" srcset="/wp-content/uploads/2018/12/Solution-Explorer.jpg 640w, /wp-content/uploads/2018/12/Solution-Explorer-300x251.jpg 300w, /wp-content/uploads/2018/12/Solution-Explorer-400x334.jpg 400w" sizes="(max-width: 640px) 100vw, 640px" /><figcaption>Solution Explorer</figcaption></figure></div>



<p>While configuring the Azure Function Output, please make sure that you are selecting the existing azure function app.</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="651" height="281" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Azure-Function-Output-Configuration.jpg" alt="" class="wp-image-13483" srcset="/wp-content/uploads/2018/12/Azure-Function-Output-Configuration.jpg 651w, /wp-content/uploads/2018/12/Azure-Function-Output-Configuration-300x129.jpg 300w, /wp-content/uploads/2018/12/Azure-Function-Output-Configuration-400x173.jpg 400w" sizes="(max-width: 651px) 100vw, 651px" /><figcaption>Azure Function Output Configuration</figcaption></figure></div>



<h3 class="wp-block-heading">Update the Script</h3>



<p>We should also do some changes in our Script.asaql file to support our newly created output.&nbsp;</p>



<pre class="wp-block-code"><code>WITH BasicOutput AS 
(
SELECT    
    messageId,
    deviceId,
    temperature,
    humidity,
    pressure,
    pointInfo,
    IoTHub,
    MAX(EventEnqueuedUtcTime) AS EventEnqueuedUtcTime,
    EventProcessedUtcTime,
    PartitionId    
FROM
    Input TIMESTAMP By EventEnqueuedUtcTime
    GROUP BY TUMBLINGWINDOW(second, 10), 
    messageId, 
    deviceId,
    temperature,
    humidity,
    pressure,
    pointInfo,
    IoTHub,
    EventEnqueuedUtcTime,
    EventProcessedUtcTime,
    PartitionId
)

SELECT * INTO SQLServerOutput FROM BasicOutput
SELECT * INTO AzureFunctionOutput FROM BasicOutput</code></pre>



<h3 class="wp-block-heading">Updating the TLS Version</h3>



<p>Once that is done, just click the button Submit to Azure, if you have any doubts in this section, read my previous posts on this topic. Now let&#8217;s log in to the portal again and see all the outputs, inputs, and the query is been published or not.</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="651" height="220" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Outputs-in-Portal.jpg" alt="" class="wp-image-13484" srcset="/wp-content/uploads/2018/12/Outputs-in-Portal.jpg 651w, /wp-content/uploads/2018/12/Outputs-in-Portal-300x101.jpg 300w, /wp-content/uploads/2018/12/Outputs-in-Portal-400x135.jpg 400w" sizes="(max-width: 651px) 100vw, 651px" /><figcaption>Outputs in Portal</figcaption></figure></div>



<p>Cool!. Well done, it seems like it is published. Now if you click on the AzureFunctionOutput, you may get a warning as &#8220;<strong>Please make sure that the Minimum TLS version is set to 1.0 on your Azure Functions before you start your ASA job</strong>&#8220;. I would rather treat this as an error instead of a warning because without making this changes our Azure Stream Analytics job will not write to our Azure Function. So this is very important, I spent many hours in this and finally found this was the root cause of my issue, you can see my answer about this <a href="https://stackoverflow.com/questions/53851553/an-error-occurred-send-events-azure-function-output-adapter-failed-to-write-eve/53851554#53851554">here</a>.</p>



<p>So just go to your Azure Function App and click on Platform Features -&gt; SSL -&gt; Minimum TLS Version</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="511" height="397" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Setting-TLS-Version.jpg" alt="" class="wp-image-13485" srcset="/wp-content/uploads/2018/12/Setting-TLS-Version.jpg 511w, /wp-content/uploads/2018/12/Setting-TLS-Version-300x233.jpg 300w, /wp-content/uploads/2018/12/Setting-TLS-Version-400x311.jpg 400w" sizes="(max-width: 511px) 100vw, 511px" /><figcaption>Setting TLS Version</figcaption></figure></div>



<p>There is a saying that developers don&#8217;t care about warning but only the errors, in some cases it is true. Hm, I was just kidding.&nbsp;</p>



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



<p>Once you are done everything mentioned, you are good to go and start your Stream Analytics job, please make sure that your MXChip is connected to a power source so that the device can start sending the data.&nbsp;</p>



<h3 class="wp-block-heading">Checking the SQL Server Output</h3>



<p>Now let&#8217;s login to our SQL Server Database and run the below query to make sure that we are getting the data from the device.</p>



<pre class="wp-block-code"><code>SELECT TOP (1000) [Id]
      ,[messageId]
      ,[deviceId]
      ,[temperature]
      ,[humidity]
      ,[pressure]
      ,[pointInfo]
      ,[IoTHub]
      ,[EventEnqueuedUtcTime]
      ,[EventProcessedUtcTime]
      ,[PartitionId]
  FROM [dbo].[StreamData] order by [EventEnqueuedUtcTime] desc</code></pre>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="651" height="286" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/SQL-Server-Output-Data.jpg" alt="" class="wp-image-13486" srcset="/wp-content/uploads/2018/12/SQL-Server-Output-Data.jpg 651w, /wp-content/uploads/2018/12/SQL-Server-Output-Data-300x132.jpg 300w, /wp-content/uploads/2018/12/SQL-Server-Output-Data-400x176.jpg 400w" sizes="(max-width: 651px) 100vw, 651px" /><figcaption>SQL Server Output Data<br></figcaption></figure></div>



<h3 class="wp-block-heading">Checking Azure Function Output&nbsp;</h3>



<p>To check the Azure Function Output, we can go back to our Azure Function and click on the Function and use the <strong>Monitor </strong>option.</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="1024" height="254" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Azure-Function-Output-Data-1024x254.jpg" alt="" class="wp-image-13487" srcset="/wp-content/uploads/2018/12/Azure-Function-Output-Data-1024x254.jpg 1024w, /wp-content/uploads/2018/12/Azure-Function-Output-Data-300x74.jpg 300w, /wp-content/uploads/2018/12/Azure-Function-Output-Data-768x190.jpg 768w, /wp-content/uploads/2018/12/Azure-Function-Output-Data-400x99.jpg 400w, /wp-content/uploads/2018/12/Azure-Function-Output-Data.jpg 1574w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Azure Function Output Data</figcaption></figure></div>



<p>Please be noted that you can always check your Azure Stream Analytics job Activity Log if you found something is not working.&nbsp;</p>



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



<p>In this article, we have learned how to,</p>



<ol class="wp-block-list"><li>work with an Azure Stream Analytics job</li><li>create an Azure Function App</li><li>create Azure Function App solution in Visual Studio</li><li>write an HttpTrigger&nbsp;function and publish the same to the Azure Function App</li><li>set up the Azure Function App as an output job topology of Azure Stream Analytics job</li><li>Use the created package in another solution</li></ol>



<p>In our next article, we will see how you can send this Azure Function Output data to an Azure SignalR service and then get the same data in an Angular Application. I can&#8217;t wait to write my next article.&nbsp;</p>



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



<p>Thanks a lot for reading. I will come back with another post on the same topic very soon.&nbsp;Did I miss anything that you may think which is needed? Could you find this post as useful? Kindly do not forget to share me your feedback.</p>



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



<p>Kindest Regards<br>Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://mail.sibeeshpassion.com/azure-function-as-output-job-topology-of-an-azure-stream-analytics-job/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>Azure Stream Analytics Job and Tools for Visual Studio</title>
		<link>https://mail.sibeeshpassion.com/azure-stream-analytics-job-and-tools-for-visual-studio/</link>
					<comments>https://mail.sibeeshpassion.com/azure-stream-analytics-job-and-tools-for-visual-studio/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Thu, 13 Dec 2018 13:13:50 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[IoT]]></category>
		<category><![CDATA[Azure IoT]]></category>
		<category><![CDATA[Data Lake]]></category>
		<category><![CDATA[MXChip]]></category>
		<category><![CDATA[Stream Analytics Job]]></category>
		<category><![CDATA[Stream Analytics tool]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=13461</guid>

					<description><![CDATA[[toc] Introduction Creating an Azure Stream Analytics job and working with them is always a fun. And what if there is a tool which helps you create a stream solution in Visual Studio so that you don&#8217;t want to go over the browser and do some manual button clicks? That&#8217;s where the Azure Data Lake and Stream Analytics Tool extension come into the play. In my previous post, we have already discussed what is an Azure Stream Analytics job and how can we work with the same, if you haven&#8217;t read the same, please read it. Now let&#8217;s go and [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>[toc]</p>



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



<p>Creating an <a href="https://sibeeshpassion.com/category/azure">Azure</a> Stream Analytics job and working with them is always a fun. And what if there is a tool which helps you create a stream solution in Visual Studio so that you don&#8217;t want to go over the browser and do some manual button clicks? That&#8217;s where the Azure Data Lake and Stream Analytics Tool extension come into the play. In my previous post, we have already discussed <a href="https://sibeeshpassion.com/an-introduction-to-azure-stream-analytics-job/">what is an Azure Stream Analytics job and how can we work with the same</a>, if you haven&#8217;t read the same, please read it. Now let&#8217;s go and use the extension.</p>



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



<p>Recently, I started working with Azure IoT Device Kit, which is a wonderful micro controller board, it can send a lot of information like temperature, humidity to the Azure cloud, as it has a lot of inbuilt sensors. Now in this article, we will create a Visual Studio solution for our Stream Analytics Job so that the same can be moved to a source control and can be easily managed.&nbsp;</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Please be noted that the Extension we are going to use is not yet supported with Visual Studio 2019, and if you try to create the same in VS2019, you will get an error as&nbsp;<a href="https://stackoverflow.com/questions/53727170/azure-stream-analytics-tool-for-visual-studio-in-2019-preview/53727171#53727171">the version of Visual Studio is not supported</a></p><cite>The extension is not supported in VS2019</cite></blockquote>



<h2 class="wp-block-heading">Setting up the Environment</h2>



<p>I am assuming that you have a valid Azure Subscription and you have access to create the resouces in it.&nbsp;</p>



<h3 class="wp-block-heading">Modify Visual Studio with Required Workloads</h3>



<p>Let&#8217;s go to our Visual Studio installer and modify the workloads now.</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="651" height="209" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Install-the-Required-Workloads.jpg" alt="" class="wp-image-13464" srcset="/wp-content/uploads/2018/12/Install-the-Required-Workloads.jpg 651w, /wp-content/uploads/2018/12/Install-the-Required-Workloads-300x96.jpg 300w, /wp-content/uploads/2018/12/Install-the-Required-Workloads-400x128.jpg 400w" sizes="(max-width: 651px) 100vw, 651px" /><figcaption>Install the Required Workloads</figcaption></figure></div>



<p>Once the workloads are modified, make sure that the extension is available in your Extensions, you can do that by going to Tools -&gt; Extension menu.</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="650" height="451" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Azure-Data-Lake-Extension.jpg" alt="" class="wp-image-13463" srcset="/wp-content/uploads/2018/12/Azure-Data-Lake-Extension.jpg 650w, /wp-content/uploads/2018/12/Azure-Data-Lake-Extension-300x208.jpg 300w, /wp-content/uploads/2018/12/Azure-Data-Lake-Extension-160x110.jpg 160w, /wp-content/uploads/2018/12/Azure-Data-Lake-Extension-400x278.jpg 400w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>Azure Data Lake Extension</figcaption></figure></div>



<h3 class="wp-block-heading">Creating a New Stream Analytics Project</h3>



<p>Once the Extension is enabled, you should be able to create a new Azure Stream Analytics Application.</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="651" height="359" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Azure-Stream-Analytics-Application.jpg" alt="" class="wp-image-13465" srcset="/wp-content/uploads/2018/12/Azure-Stream-Analytics-Application.jpg 651w, /wp-content/uploads/2018/12/Azure-Stream-Analytics-Application-300x165.jpg 300w, /wp-content/uploads/2018/12/Azure-Stream-Analytics-Application-400x221.jpg 400w" sizes="(max-width: 651px) 100vw, 651px" /><figcaption>Azure Stream Analytics Application&nbsp;</figcaption></figure></div>



<p>The new project will be containing the below files.</p>



<ol class="wp-block-list"><li>Input.json</li><li>Output.json</li><li>JobConfig.json</li><li>Script.asaql</li></ol>



<p>To&nbsp;configure your subscription, please make sure that you have added your&nbsp;Subscription in the Server Explorer.</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="435" height="544" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Azure-Server-Explorer.jpg" alt="" class="wp-image-13470" srcset="/wp-content/uploads/2018/12/Azure-Server-Explorer.jpg 435w, /wp-content/uploads/2018/12/Azure-Server-Explorer-240x300.jpg 240w, /wp-content/uploads/2018/12/Azure-Server-Explorer-400x500.jpg 400w" sizes="(max-width: 435px) 100vw, 435px" /><figcaption>Azure Server Explorer</figcaption></figure></div>



<p>The Input.json file is the replica of your Input job topology, <g class="gr_ gr_120 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="120" data-gr-id="120">double click</g> on the file will give you the configuration page to configure the details.&nbsp;</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="1024" height="982" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Input-Configuration-1024x982.jpg" alt="" class="wp-image-13466" srcset="/wp-content/uploads/2018/12/Input-Configuration-1024x982.jpg 1024w, /wp-content/uploads/2018/12/Input-Configuration-300x288.jpg 300w, /wp-content/uploads/2018/12/Input-Configuration-768x736.jpg 768w, /wp-content/uploads/2018/12/Input-Configuration-400x384.jpg 400w, /wp-content/uploads/2018/12/Input-Configuration-626x600.jpg 626w, /wp-content/uploads/2018/12/Input-Configuration.jpg 1504w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Input Configuration</figcaption></figure></div>



<p>The Output.json file is your output job topology, you can have as many outputs you need. In my case it is just one, SQL Server Database.&nbsp;</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="650" height="485" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Output-Configuration.jpg" alt="" class="wp-image-13467" srcset="/wp-content/uploads/2018/12/Output-Configuration.jpg 650w, /wp-content/uploads/2018/12/Output-Configuration-300x224.jpg 300w, /wp-content/uploads/2018/12/Output-Configuration-400x298.jpg 400w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>Output Configuration</figcaption></figure></div>



<p>You can always configure your job using the JobConfig.json file. When you configure the Job, you need to be sure about the values you are providing and what are the needs of them.&nbsp;</p>



<p><strong>Data Locale</strong> is your locale input. The option <strong>Output Error Handling</strong> is for handling the situation when the events fail to be written to the output, you can select either Drop or Retry. The <strong>Late Arrival Tolerance Window</strong> is the timeframe which you can wait for the event to reach the IoT hub, the time difference is between the event timestamp and the system time. </p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="650" height="416" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/JobConfiguration.jpg" alt="" class="wp-image-13468" srcset="/wp-content/uploads/2018/12/JobConfiguration.jpg 650w, /wp-content/uploads/2018/12/JobConfiguration-300x192.jpg 300w, /wp-content/uploads/2018/12/JobConfiguration-400x256.jpg 400w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>Job Configuration</figcaption></figure></div>



<p>And the Script.asaql is the file where you need to add your custom query which gets data from the input and send it to the output.&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>Once everything is done, you are ready to submit the same to the Azure. You can either create a new job or use the existing one.&nbsp;</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="651" height="280" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Submit-Job.jpg" alt="" class="wp-image-13469" srcset="/wp-content/uploads/2018/12/Submit-Job.jpg 651w, /wp-content/uploads/2018/12/Submit-Job-300x129.jpg 300w, /wp-content/uploads/2018/12/Submit-Job-400x172.jpg 400w" sizes="(max-width: 651px) 100vw, 651px" /><figcaption>Submit Job</figcaption></figure></div>



<p>When you submit, you can see that a new Stream Analytics view will get opened and the job will be starting automatically. You can always see the blobs created under your container by going to the cloud explorer.&nbsp;</p>



<figure class="wp-block-image"><img decoding="async" width="650" height="300" src="https://sibeeshpassion.com/wp-content/uploads/2018/12/Cloud-Explorer-Blob-Container-View.jpg" alt="" class="wp-image-13471" srcset="/wp-content/uploads/2018/12/Cloud-Explorer-Blob-Container-View.jpg 650w, /wp-content/uploads/2018/12/Cloud-Explorer-Blob-Container-View-300x138.jpg 300w, /wp-content/uploads/2018/12/Cloud-Explorer-Blob-Container-View-400x185.jpg 400w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>Cloud Explorer</figcaption></figure>



<p>Now just right click on your solution and select &#8220;Add solution to Source Control and then push the same to your git repository. Once you have added the solution to the source control, your team members can easily update the Input and Output configuration and have a history of the same.&nbsp;</p>



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



<p>In this article, we have learned how to,</p>



<ol class="wp-block-list"><li>set up the Visual Studio for using Data Lake and Stream Analytics tool</li><li>use the Data Lake and Stream Analytics tool</li><li>configure the Input for Stream Analytics</li><li>configure the Stream Analytics Job</li><li>Use the created package in another solution</li></ol>



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



<p>Thanks a lot for reading. I will come back with another post on the same topic very soon.&nbsp;Did I miss anything that you may think which is needed? 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://mail.sibeeshpassion.com/azure-stream-analytics-job-and-tools-for-visual-studio/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>An Introduction to Azure Stream Analytics Job</title>
		<link>https://mail.sibeeshpassion.com/an-introduction-to-azure-stream-analytics-job/</link>
					<comments>https://mail.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 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://mail.sibeeshpassion.com/an-introduction-to-azure-stream-analytics-job/feed/</wfw:commentRss>
			<slash:comments>8</slash:comments>
		
		
			</item>
	</channel>
</rss>
