Windows Azure Service Bus Queues Demo
Total Page:16
File Type:pdf, Size:1020Kb
Demo Script Windows Azure Service Bus Queues
Lab version: 1.0.0 Last updated: 4/3/2018
Contents
Overview
This document provides setup documentation and step-by-step instructions for showing a demo of Windows Azure. This document can also serve as a tutorial or walkthrough of Windows Azure Service Bus Queues. In this demo, you will walk through the code that is used to send and receive messages onto the Windows Azure Service Bus Queues.
Note: In order to run through this complete demo, you must have network connectivity.
1. Key Messages In this demo you will see the following features How to connect to a Windows Azure Service Bus namespace. How to send messages to a Windows Azure Service Bus Queue. How to receive messages from a Windows Azure Service Bus Queue.
2. Key Technologies This demo uses the following technologies: .NET Framework 4 Visual Studio 2010 Windows Azure SDK and Windows Azure Tools for Microsoft Visual Studio Windows Azure Service Bus (i.e. internet connectivity is required)
3.
4. Time Estimates Estimated time for setting up and configuring the demo: 10 min Estimated time to complete the demo: 5 min
5.
Setup and Configuration
The setup and configuration for this demo involves the following tasks: Create a Service Bus Namespace in your Windows Azure subscription. Update the solutions with your newly created Service Namespace settings. Publish the ServiceBusDemo-Cloud solution.
6.
Task 1 – Creating a Service Bus Namespace Navigate to the Windows Azure portal. You will be prompted for your Windows Live ID credentials if you are not already signed in. Click Service Bus, Access Control & Caching link in the left pane, and then select Service Bus item under the Services element. In the upper ribbon, click New and create a new Service Namespace. Make sure the ServiceBus box is selected Locate the Properties of the newly created Service Namespace and record the name. Then, click the View button inside the Default Key box and record the values of the Default Issuer and the Default Key as well. You will use them in the next task.
7. Task 2 – Updating the Solutions with the Service Namespace Settings Open the ServiceBusDemo-Cloud.sln solution located in the Code folder of this demo. Locate the ServiceBusDemo.Azure project and expand the role folder. Open the Properties of the ServiceBusDemo role. Switch to the Settings tab and update the ServiceNamespace, ServiceIssuer and ServiceSecret with the values recorded in the previous task. Update the QueueName value with the name you want, without spaces (e.g.: myqueue). Now, open the ServiceBusDemo-OnPremises.sln solution located in the Code folder of this demo. Edit the app.config file and replace the placeholders with the same values you used in the step 3.
8. Task 3 – Publishing the ServiceBusDemo-Cloud Solution If not already open, double-click the ServiceBusDemo-Cloud.sln solution located in the Code folder of this demo. To publish the application in the cloud, right-click the ServiceBusDemo.Azure project and select Publish. Follow the steps of the Publish Windows Azure Application wizard and then click Publish. Wait for the deployment operation to complete.
9.
Demo Flow
The following diagram illustrates the high-level flow for this demo and the steps involved: Figure 1 Demo Flow
Opening Statement
In this demo, we are going to walk through the code used to connect to a Windows Azure Service Bus namespace and either send or receive messages through a Windows Azure Service Bus Queue. Step-by-Step Walkthrough
This demo is composed of the following segments: Show the communication between two applications using ServiceBus Queues
10.
11. Segment #1: Show the communication between two applications using ServiceBus Queues
Action Script Screenshot
Open Visual Studio as administrator I’m going to show you how to use from Start | All Programs | one of the messaging capabilities Microsoft Visual Studio 2010 by built-in in Windows Azure: right clicking the Microsoft Visual Service Bus Queues. Studio 2010 shortcut and choosing Run as administrator. Basically, we have an ASP.NET application hosted in Windows Open the ServiceBusDemo- Azure that sends messages to a Cloud.sln solution located in the Windows Azure Service Bus Code folder of this demo. Queue. Then, a client connected to the same queue will pull messages from it. Show the solution structure in Solution Explorer. The ServiceBusDemo project will act as the front-end. Is a simple application with a simple form, an input to write a message and a submit button. You can see that in 5 small lines of code the application connects to Open the HomeController.cs file the queue and sends the inside the Controllers folder. message.
Highlight the code in the First, you need to construct SendMessage method that the Service Bus URI. sends a message to a Service Bus Queue. Then, you create a MessagingFactory object. This is the anchor class Open a browser and navigate to used for run-time http://[YOUR-HOSTED- operations to send and SERVICE].cloudapp.net, where receive to and from [YOUR-HOSTED-SERVICE] is queues. the DNS Prefix of the Hosted Service you created in the Setup Next, a QueueClient is Section of this Demo. created with a specific name. Note that we’re Mention that the Web application is explicitly setting already deployed to a Windows PeekLock mode for this Azure Hosted Service. client. This mode is used to keep the received message hidden from other listeners.
Lastly, we initialize a new instance of a BrokeredMessage with the actual message in its body and we send it through the queue. This class represents the unit of communication between ServiceBus clients.
I’ve already deployed the application to a Windows Azure Hosted Service. Run a new instance of Visual Studio Now let’s inspect the back-end, as Administrator. which is basically a console application that listens to the queue. Open the ServiceBusDemo- OnPremises.sln solution located in the Code folder of this demo. You can see that we use the same code to create the QueueClient, but this time we are going to use Open the Program.cs file. this object to receive messages in a while loop. Highlight the code in the Main method that creates a long Note that we’re using the Complete() polling thread to receive method after we write the messages from a Service Bus message in the Console. This is Queue. because we want to delete the message after it is consumed. Press CTRL+F5 to start the Console Now that we have gone through the application without debugging. code, let’s try the application.
To send a message through the We can use the front-end to send ServiceBus Queue, type Hello messages through the Queue, Scott! in the box and click Send. for example we type Hello Scott! In the box and click Send. Switch to the Console application and show the message received. We can see that after a few second the back-end receives the message Type Lookin’ Good in the box and click Send. Let’s try again but this time we type Lookin’ good. Switch to the Console application and show the message received. If at any point the back-end application crashes or it’s taken Close the Console application. down, we can still add messages into the queue that will be pulled Switch back to the browser and send out later. another message saying Oh no! Where’d you go? You can browse to the front-end if you want and start sending Switch to Visual Studio and press messages to the queue. I can CTRL+F5 to start the Console add more listeners as well to application again without receive the messages. debugging.
Once the Console application starts, wait a few seconds until the message is received.
Switch back to the browser and send another message saying Ah there you are. Close the Console application.
Mention that people can hit the http:// [YOUR-HOSTED- SERVICE].cloudapp.net web site hosted in Windows Azure and send their own messages.
Summary
This demo showed how to connect to a Windows Azure Service Bus namespace and how to send and receive messages through a Windows Azure Service Bus.
Known Issues
Please note the following known issues with this demo: None.