Using Azure Service Bus Queues with C#, Cloud Shell, PowerShell, and CLI

1 hour
  • 3 Learning Objectives

About this Hands-on Lab

In this lab, you will gain experience using C#, the Azure Cloud Shell/PowerShell/CLI, and Visual Studio to connect to and use Azure Service Bus queues.

You will use the Azure Cloud Shell to create a Service Bus namespace and queue. Then, you’ll RDP into a Windows VM and update a pre-built Visual Studio solution with the appropriate C# code to connect to the queue, send messages to the queue, and subscribe to the queue to read messages. When you’re finished, you will run the console application to see everything working. Finally, you will verify messages were sent and received from the queue using the Azure portal.

Upon completion of the lab, you will have gained the experience required to work with Azure Service Bus queues using C#.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Set up Cloud Shell and use PS/CLI to create a Service Bus namespace and queue.

PowerShell script to create namespace and queue:

# ------------------------
# az servicebus namespace create
# az group list
# az servicebus queue create
# ------------------------

# create a Service Bus namespace and queue
$resourceGroup = _______________ --query '[0].name' --output json
$namespaceName  = "LALab" + (Get-Date).ticks

_______________ --resource-group $resourceGroup --name $namespaceName --location southcentralus
_______________ --resource-group $resourceGroup --namespace-name $namespaceName --name myQueue
#
RDP into the VM, open the VS solution, and set up Cloud Shell.

RDP login:

  UserName : "azureuser"
  Password : "LA!2018!Lab"

PowerShell to run:

Add-Type -Path "C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.5System.IO.Compression.FileSystem.dll"

$url = "https://github.com/linuxacademy/content-azure-labs/blob/master/zips/azure-service-bus-queues.zip?raw=true"
$zipfile = "C:UsersazureuserDesktopazure-service-bus-queues.zip"
$folder = "C:UsersazureuserDesktop"

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -UseBasicParsing -OutFile $zipfile $url 

[System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $folder)

Remove-Item -Path $zipfile 
#
Update Visual Studio solution and run the console app.

In this step, we’ll update our Visual Studio solution with the appropriate C# code to connect to and interact with the Service Bus queues.

When we’re finished, we’ll run our completed console app to send messages to the queue and subscribe to the queue to read messages.

We’ll also verify the messages were saved through the Azure portal.

Additional Resources

As a developer, you want to use the Azure Service Bus SDK and C# code to connect to and interact with Azure Service Bus queues.

To do this, you will RDP into a virtual machine in Azure, download a pre-built solution, and use the Cloud Shell to create a Service Bus namespace and queue. Then, in the solution, you will fill in the correct C# code to get the program to compile. When you run the program, it will save and retrieve messages from a queue in the Azure Service Bus. Finally, you will verify messages were sent and received from the queue using the Azure portal.

The activity gives step-by-step instructions for this lab. Follow along with them and you will successfully connect to and interact with Azure Service Bus queues.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$2,495.00

Checkout
Sign In
Welcome Back!
Thanks for reaching out!

You’ll hear from us shortly. In the meantime, why not check out what our customers have to say about ACG?