Demo Script
Using Queues
Lab version: 1.0.0
Last updated: 12/3/2009
Prepared by: David Aiken
Contents
Overview 3
Key Messages 3
Key Technologies 3
Time Estimates 4
Setup and Configuration 4
Task 1 –Run the dependency checker 4
Demo Flow 5
Opening Statement 6
Step-by-Step Walkthrough 6
Sending the message 6
Reading and processing the message 9
Summary 10
Overview
This document provides setup documentation, step-by-step instructions, and a written script for showing a demo of Windows Azure. This document can also serve as a tutorial or walkthrough of the technology. In this demo, you will walk through the code that is used to put and get messages onto the Windows Azure queue. For additional demos of the Azure Services Platform, please visit http://www.azure.com.
Note: You do not require an internet connection, or a Windows Azure account for this demo.
Key Messages
In this demo you will specifically see four things:
1. How to create a connection to a Queue.
2. Put a message into a Queue.
3. Get a message from a Queue.
4. Delete a message from a Queue.
Key Technologies
This demo uses the following technologies:
1. .NET Framework 3.5 SP1
2. Visual Studio 2008 SP1 or Visual Web Developer 2008 SP1
3. Windows Azure SDK – November 2009 CTP or later
4. Windows Azure Tools for Microsoft Visual Studio November 2009 CTP or later
5. Windows Azure Services
Time Estimates
· Estimated time for setting up and configuring the demo: 10 min
· Estimated time to complete the demo: 10 min
Setup and Configuration
This demo does not have any advanced configuration requirements. You simply need to have the pre-requisites installed and have a developer account for Windows Azure.
Task 1 –Run the dependency checker
The following steps describe how to run the Dependency Checker utility included with the lab to verify that you have the pre-requisite components properly installed. You can skip this exercise if you are confident that the pre-requisites are properly installed and configured.
1. Run the StartHere.cmd command script located in the directory that contains this demo.
2. The StartHere.cmd script will launch the Configuration Wizard. The Configuration Wizard is designed to check your machine to ensure that it is properly configured with all of the dependencies to build and use the Azure Services Platform Management Tools.
3. Click through the steps in the Configuration Wizard. The Required Software step will perform the actual scan of your machine. If you do not have the necessary dependencies, then install them using the links provided by the dependency checker and rescan your machine.
Demo Flow
The following diagram illustrates the high-level flow for this demo and the steps involved:
Opening Statement
In the next few minutes we’ll see how you can use a Queue to pass work items between a web role and worker role.
In this demo you will specifically see four things:
1. How to create a connection to a Queue.
2. Put a message into a Queue.
3. Get a message from a Queue.
4. Delete a message from a Queue.
Step-by-Step Walkthrough
This demo is composed of the following segments:
· Sending the message
· Reading and processing the message
Sending the message
Action / Script / Screenshot1. Start Visual Studio 2008 or Visual Web Developer 2008 SP1
2. Select File -> Open Project
3. Select GuestBook.sln / · Let’s Open an existing Windows Azure project.
· In the following demos we are going to use the Guestbook application.
· The Guestbook application is a simple application that exercises many features of the Windows Azure platform.
4. Once the solution is open, point out the projects:
a. GuestBook_Data contains the classes for the data entities used by table storage
b. GuestBook is the cloud project. This is what defines the structure of the cloud solution, which roles are present and any service configuration.
c. GuestBook_WebRole is the ASP.NET project for the web role
d. GuestBook_WorkerRole is the worker role, written in VB. / · As you can see we have several projects
· Most of the projects are simply either standard class libraries, or ASP.NET web sites.
· The important project for us is GuestBook.
· This defines the structure of our service.
· You can see it has 2 roles, GuestBook_WebRole provides the web role, and GuestBook_WorkerRole provides the worker role.
· When you sign the guestbook, an image is uploaded to blob storage. This image is then resized by the worker role. The worker role gets the information about the image to resize from a message put in the queue from the web role.
· This pattern is a common way to decouple tasks and use the worker role.
5. Open the ServiceConfiguration.cscfg file. / · Because the GuestBook application uses the Storage Client assembly, we have to add the queue configuration to the ServiceConfiguration file.
· DataConnectionString is configured to use the local development storage.
6. Press F5 to start the application.
7. Right click on the Windows Azure icon in the system tray and click “Show Development Storage UI” / · If we take a look at the local Development Storage, we can see the endpoints for the 3 storage services.
· The UI also allows us to restart the development storage, as well as “Reset” the storage.
· Resetting the storage clears the contents, which is useful for testing.
· You can also stop and start the services, which again is useful for testing error handling and failures.
8. Open the Default.aspx.cs file (InitializeStorage method) and locate and highlight the code shown / · Now let’s take a look at the code that puts the message in the queue.
· First, similar to the blob storage, we have to create a reference to the CloudQueueClient.
Highlight the code shown / · Next we need to get a reference to the Queue.
· Getting a reference to a queue does not check for its existence, so we should check the queue exists, and if not create it.
9. Highlight the code shown (SignButton_Click method) / · Finally, we can put a message in the queue.
· In this example, we simply construct a common separated string that can be easily parsed by the worker. The string contains the 3 things
a. The name of the blob containing the image
b. The partitionKey of the entity that was added to the table when the guestbook was signed.
c. The rowKey of the entity that was added to the table when the guestbook was signed.
Reading and processing the message
Action / Script / Screenshot1. Open the WorkerRole.vb file from the worker project.
2. Highlight the code shown (OnStart method) / · Now that we have written a message to the queue, how do we read it?
· Looking in the worker role, we see we have the same code to setup the connection to the queue, only this time its written in VB.NET
3. Highlight the code shown (Run method) / · In our main worker loop, we read the message from the Queue.
· If the message is not null or nothing, then we have a message. If not we should do nothing for a while and try again.
· We can get at the contents of the string using the AsString property.
· Here we split the string into an array containing each comma separated element.
Highlight the code shown / · Once we have processed the message, we need to remove it from the queue. We do this by calling DeleteMessage on the queue, and passing the message to delete.
· This will permanently remove the message from the queue.
· If we don’t call DeleteMessage, then the message will get put back on the queue after around 30 seconds, and the message will be available for processing again.
Summary
In this demo, you saw how we can write and read simple messages to the Windows Azure Queue.