Use 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.

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
  1. Run PowerShell as administrator and create the needed Azure resources.
    
    # create a Service Bus namespace and queue
    $resourceGroup = az group list --query '[0].name' --output json
    $namespaceName  = "LALab" + (Get-Date).ticks

az servicebus namespace create –resource-group $resourceGroup –name $namespaceName –location [Enter your lab’s Resource Group location here]
az servicebus queue create –resource-group $resourceGroup –namespace-name $namespaceName –name myQueue
#

Download the C# Code and Launch the VS Solution

RDP login:

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

PowerShell to run:

$url = "https://github.com/ACloudGuru-Resources/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

Expand-Archive -LiteralPath $zipfile -DestinationPath $folder

Remove-Item -Path $zipfile
Update Visual Studio Solution and Run the Console App
  1. Modify the partially completed C# code that was provided to allow interaction with the Service Bus queues.

  2. Begin the process of sending messages.

  3. Observe the message count in the Azure Service Bus Queue is showing ten messages.

  4. Return to your VM and press any key to receive the messages.

  5. Observe the message count in the Azure Service Bus queue is showing zero messages.

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.

RDP Connection Methods

Windows Users:

Check out the following link for connecting via RDP in Windows: https://support.microsoft.com/en-us/windows/how-to-use-remote-desktop-5fe128d5-8fb1-7a23-3b8a-41e636865e8c.

Mac Users:

To connect via RDP on a Mac, you will need additional software. This software from Microsoft is available for free to connect from MacOS: https://apps.apple.com/us/app/microsoft-remote-desktop/id1295203466?mt=12.

Linux Users

As there are many different flavors and distributions of Linux, there isn't a best method for connecting via RDP that fits all distributions that we can recommend. Some options to consider are FreeRDP, rDesktop, Remmina, or Vinagre depending on your OS.

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.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?