Demo Script
Using the Worker Role
Lab version:2.0.0
Last updated:10/16/2018
Contents
Overview
Key Messages
Key Technologies
Time Estimates
Setup and Configuration
Task 1 –Run the dependency checker
Demo Flow
Opening Statement
Step-by-Step Walkthrough
Reviewing the worker role code
Summary
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 demoyou will demonstrate the basic components of a worker role. The project is provided, and there are no coding steps. For additional demos of the Azure Services Platform, please visit
Note: You do not need internet connectivity for this demo as everything is performed locally.
Key Messages
In this demo you will see three things:
- You will see that Windows Azure can host other languages other than C#
- You will learn that worker roles are simple class libraries, with a class inheriting from RoleEntryPoint. Think of workers as a console application, or a Windows Service.
- You will see the interaction points used by the fabric to start, stop and get the health status.
Key Technologies
This demo uses the following technologies:
- .NET Framework 4
- Visual Studio 2010
- Windows Azure SDK
- Windows Azure Tools for Microsoft Visual Studio
- 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-requisitesare properly installed and configured.
- Run the StartHere.cmd command script located in the directory that contains this demo.
- 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.
- 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:
Figure 1
Demo Flow
Opening Statement
In the next few minutes we’ll take a look at how you can implement a worker role. In the interests of time, we will examine an existing worker role in the Guestbook service.
In this demo you will specifically see three things:
- You will see that Windows Azure can host other languages other than C#
- You will learn that worker roles are simple class libraries, with a class inheriting from RoleEntryPoint. Think of workers as a console application, or a Windows Service.
- You will see the interaction points used by the fabric to start, stop and get the health status.
Step-by-Step Walkthrough
This demo is composed of the following segments:
- Reviewing the worker role code
Reviewing the worker role code
Action / Script / Screenshot- Start Visual Studio 2010 or Visual Web Developer 2010
- Select File -> Open Project
- Select GuestBook.sln
- Let’sOpen 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.
- Once the solution is open, point out the projects:
- GuestBook is the cloud project. This is what defines the structure of the cloud solution, which roles are present and any service configuration.
- GuestBoos_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 two roles, GuestBook_WebRole provides the web role, and GuestBook_WorkerRole provides the worker role.
- Expand the GuestBook_WorkerRole
- Now lets take a look in more detail at the worker role.
- The first thing to notice is that the GuestBook_WorkerRoleis actually written in VB. Windows Azure can execute any .NETFramework code, including VB.Net.
- The next thing to notice is that the project is in fact a class library.
- Open the WorkerRole.vb file
- Point out the imports statement
- Point out the class inherits from RoleEntryPoint
- There is only 1 class in the project, which represents the worker role.
- First we have some imports to the referenced Microsoft.WindowsAzure.ServiceRuntime.
- This namespace contains the API for Windows Azure, including the RoleEntryPoint, which this class inherits from.
- RoleEntryPoint provides several methods which are called by the fabric to start, stop and get the health status of the worker.
- Navigate to the Run method.
- The Run method is the method that is called by the fabric once the worker is deployed and ready to run.
- The run method is where you should perform your worker tasks.
- You should not return from the Run method. This is seen as an error by the fabric, and your worker role can be restarted.
- Show the while true loop
- In this sample, the start method contains a while true loop never exits.
- The actual work carried out by the queue is irrelevant in this demo, we’ll take a look at it in a later demo.
- Navigate to the OnStart method.
- Override the OnStart method to run initialization code for your role.
- If the OnStart method returns false, the instance is immediately stopped. If the method returns true, then Windows Azure starts the role by calling the Run method.
- A web role can include initialization code in the ASP.NET Application_Start method instead of the OnStart method. Application_Startis called after the OnStart method.
- Any exception that occurs within the OnStart method is an unhandled exception.
- Type Public Overrides, then press space, then choose OnStop()
- There is 1 more method we may wish to implement depending upon our design.
- This is the OnStop method.
- OnStopis called whenever the fabric is going to shutdown your worker role – for whatever reason. It’s up to you to respond within a timely fashion, otherwise your worker role will simply be “killed”.
- You have around 20 seconds to respond to a stop method.
- OnStopis not called when an actual hardware or other catastrophic failure occurs. For this reason, you may choose not to implement stop, and instead write your worker to handle failures.
- As a reminder, when writing worker roles you can use any supported .NET language.
Summary
In this demo, you saw how a worker role is constructed, which interaction points there are and how to respond to start/stop calls.