Deploying compute workloads by using images and containers Part 2 – Deploy a Docker container image to Container Registry

Now let’s deploy a docker container to an Azure Container Registry.

Launch the cloudshell from the Azure Portal and create a folder and a dotnet console application.

cd clouddrive
mkdir ipcheck
cd ipcheck/

Create a new console project

dotnet new console

Create a new file called Dockerfile and launch code inside the cloudshell.

Copy the sourcecode from the learn excercise and run the application to verify that the ipaddress is found.

And finally copy the sourcecode to the Dockerfile, save and close.

Now in the next part we will create an Azure container registry and publish our ipcheck console application!

Asynchronously processing messages by using Azure Queue Storage Part 4 – Download Azure Storage Explorer and add messages to the queue.

Head over to Azure Storage Explorer here and download and install.

Open and connect to your storage account and queue and add a message. Make sure you don’t encode in base64.

Run your dotnet application and watch it collect your message in your very own Azure Storage Queue!

You’ve just created a storage account, message queue and written a C# program that uses the resources. Great work!

Now go ahead and delete the storage account and the resource group if you don’t want them anymore.

az storage account delete -n lab11stgacc -g lab11-rg
az group delete -g lab11-rg

Asynchronously processing messages by using Azure Queue Storage Part 2 – Install Git, pull a repository and connect to a storage queue using C#

Head over to GIT, download and install.

Open VSCode, press ctrl+shift p and type to clone a git and the link to the git.

Next, create the project, install and build it. Please visit the github site here to see all the commands.

Now open the Project.cs file and update the code with the code from the github and edit the code with the connection string you collected when you create the storage account.

Next update the main to connect and create the queue.

Next, save and run! In the next post we’ll add messages to the queue.

Asynchronously processing messages by using Azure Queue Storage Part 1 – Create a storage account

Microsoft provides many different sources for working with Azure. Let’s run through Microsoft Learning Github and Module 11 of AZ-204: Developing solutions for Microsoft Azure here.

Let’s create a storage account using CLI.

First create the resource group.

az group create -n lab11-rg -l westeurope

Now let’s create a storage in that resource group.

az storage account create -n lab11stgacc -g lab11-rg -l westeurope --sku Standard_LRS

Now finally let’s get and record our connection string storage key using CLI.

az storage account show-connection-string --name lab11stgacc

Great! Make a note of this connection string as we’ll need it later.

In the next post we’ll install git and pull the lab into our Visual Studio Code!

Send and receive messages from Azure Event Hubs using .Net Part 5 – Create the app receiver to receive Azure Event Hub messages

Let’s continue the quickstart and create our receiver app. Right click and create a new project and place it in the same folder as the send project.

Use Nuget and install two new packages. Make sure that you are in the correct project when you use nuget.

Install-Package Azure.Messaging.EventHubs
Install-Package Azure.Messaging.EventHubs.Processor

Now it’s time to add some code.

Update the using with our new packages.

using System;
 using System.Text;
 using System.Threading.Tasks;
 using Azure.Storage.Blobs;
 using Azure.Messaging.EventHubs;
 using Azure.Messaging.EventHubs.Consumer;
 using Azure.Messaging.EventHubs.Processor;

Write constants for our connections.

private const string ehubNamespaceConnectionString = "";
     private const string eventHubName = "";
     private const string blobStorageConnectionString = "";
     private const string blobContainerName = "";

And update the main with our new .Net Core app.

static async Task Main()
     {
         // Read from the default consumer group: $Default
         string consumerGroup = EventHubConsumerClient.DefaultConsumerGroupName;
     // Create a blob container client that the event processor will use      BlobContainerClient storageClient = new BlobContainerClient(blobStorageConnectionString, blobContainerName);     // Create an event processor client to process events in the event hub     EventProcessorClient processor = new EventProcessorClient(storageClient, consumerGroup, ehubNamespaceConnectionString, eventHubName);     // Register handlers for processing events and handling errors     processor.ProcessEventAsync += ProcessEventHandler;     processor.ProcessErrorAsync += ProcessErrorHandler;     // Start the processing     await processor.StartProcessingAsync();     // Wait for 10 seconds for the events to be processed     await Task.Delay(TimeSpan.FromSeconds(10));     // Stop the processing     await processor.StopProcessingAsync(); }

And finally add event handler and error handler.

static async Task ProcessEventHandler(ProcessEventArgs eventArgs)
     {
         // Write the body of the event to the console window
         Console.WriteLine("\tRecevied event: {0}", Encoding.UTF8.GetString(eventArgs.Data.Body.ToArray()));
     // Update checkpoint in the blob storage so that the app receives only new events the next time it's run     await eventArgs.UpdateCheckpointAsync(eventArgs.CancellationToken); } static Task ProcessErrorHandler(ProcessErrorEventArgs eventArgs) {     // Write details about the error to the console window     Console.WriteLine($"\tPartition '{ eventArgs.PartitionId}': an unhandled exception was encountered. This was not expected to happen.");     Console.WriteLine(eventArgs.Exception.Message);     return Task.CompletedTask; }

Now run the receiver project and you will see the events you sent earlier.

To make things a bit more fun jump into your send project and update the code with some strings and also add a fourth event!

            // Add events to the batch. An event is a represented by a collection of bytes and metadata.              eventBatch.TryAdd(new EventData(Encoding.UTF8.GetBytes("My event")));             eventBatch.TryAdd(new EventData(Encoding.UTF8.GetBytes("in ")));             eventBatch.TryAdd(new EventData(Encoding.UTF8.GetBytes("Azure Hub")));             eventBatch.TryAdd(new EventData(Encoding.UTF8.GetBytes("Is here!")));             // Use the producer client to send the batch of events to the event hub             await producerClient.SendAsync(eventBatch);             Console.WriteLine("A batch of 4 events has been published.");

Now run both the send and the receive again and the output will be as below.

There you go! You’ve just created two .NET Core apps, storage accounts and an Azure Event Hub. Well done!

Send and receive messages from Azure Event Hubs using .Net Part 4 – Create a storage account as a checkpoint store

Now it’s time to create the storage account and get the connecting string for our .Net Core app.

First create the storage account by logging in to Azure CLI and place it in the same Resource Group and your Event Hub.

az storage account create \
     --name  \
     --resource-group storage-resource-group \
     --location westus \
     --sku Standard_RAGRS \
     --kind StorageV2

Next create the blob account. Go into Azure and select your new storage and create a blob container.

Finally copy the storage connection string for the storage account.

Now in the next post we’ll create our code and receive some Event Hub messages!

Send and receive messages from Azure Event Hubs using .Net Part 3 – Write the .Net console app for sending messages to the Azure Event Hub

Following the Microsoft Docs quickstart let’s write some code from their instructions!

Add the using statements in the programs.cs file

 using System;
 using System.Text;
 using System.Threading.Tasks;
 using Azure.Messaging.EventHubs;
 using Azure.Messaging.EventHubs.Producer;

Next go and get the namespace connection string and copy this so we can add the connection string to our code.

And inside the class add the constants and get the connection string and eventhub name from your event hub and copy them

private const string connectionString = "";
private const string eventHubName = "";

Finally replace the Main method with the method described in the link and build the project!

Now run the project and watch your three events being sent to your very own Azure Event Hub!

And inside your event hub you can now see the metrics updated.

Now in the next post we’ll create a storage and an app to receive the messages.