After logging in, you can see your all active subscriptions in the output and you need to set the subscription for this current context. To do so use the following command. I have multiple subscriptions and I will use my Azure pass sponsorship for this context.
- az account set --subscription "Azure Pass - Sponsorship"
Step 2 - Create an Azure Resource Group Using Portal and CLI
As you know, we already logged in using CLI. Now we will create a resource group for the Azure web app and app service plan. We will keep our all resources in this resource group that we are creating. Use the following command in order to create the resource group.
- az group create --name "datalake-rg" --location "centralus"
Step 3 - Create Azure Data Lake Storage Gen2 Account
Click on create a new resource and search storage account and choose the storage account from the result. You can also use the following commands in order to create the storage account using Azure CLI.
- # Create managed identity
- az identity create -g <RESOURCEGROUPNAME> -n <MANAGEDIDENTITYNAME>
-
- az extension add --name storage-preview
-
- az storage account create --name <STORAGEACCOUNTNAME> \
- --resource-group <RESOURCEGROUPNAME> \
- --location eastus --sku Standard_LRS \
- --kind StorageV2 --hierarchical-namespace true
Choose your subscription, resource group, and storage account name and click Next: Networking >
The networking, tab these are the default selected options and maybe you want to use another one but for this demo please use the default selected options and hits Next: Data Protection >
The data protection, tab these are the optional option you want to use but for this demo please also use the default selected options and hits Next: Data Protection >
The advance, tab is the default selected option and maybe you want to use another one but for this demo please use the default selected options and choose the enable against the Data Lake Storage Gen2 option, and hits Next: Tags > and next review + create.
After creating the azure data lake gen2 account, open the newly created azure data lake storage gen2 account.
Step 4 - Create Azure Data Lake Container
Select the container option from the left navigation. Click on the + Container button and create a new container.
Step 5 - Upload Avro File
Open the newly created container and upload an Avro file inside the container. I also attached the sample Avro file on the top. You can download and use it for your learning.
Step 6 - Create a new Console App in Visual Studio 2019
Open the visual studio and create a new project and add a console app (.Net Core) with C#.
Step 7 - Add References to NuGet Packages
First of all, in References, add the references to WindowsAzure.Storage, Microsoft.Avro.Core and Newtonsoft.Json using NuGet Package Manager, as shown below.
Step 8 - Add Sensor Model Class
Add a new class to your project with the name SensorModel.cs. Add the following properties to get the result set from JSON response with an appropriate namespace.
(FileName: SensorModel.cs)
- public class SensorModel
- {
- public string refid { get; set; }
- public long measuringpointid { get; set; }
- public long dateid { get; set; }
- public long timeid { get; set; }
- public string timestamp { get; set; }
- public double value { get; set; }
- public override string ToString()
- {
- return $"DateTime: {timestamp:HH:mm:ss} | MeasuringPointId: {measuringpointid} | "
- + $"Date: {dateid} | Serialnumber: {refid} | SensorValue: {value} ";
- }
- }
Open the Program class and replace the following code with an appropriate namespace. Please grab your connection string from your storage account and replace it in the code and also use your container name inside the code.
Run your console app and then you will see the following output in the console.